注册 登录
编程论坛 C# 论坛

本人初学者,为什么会出现下面的问题?求大神赐教。。

锋100 发布于 2014-02-26 12:42, 1261 次点击
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{
    public partial class ViewerForm1 : Form
    {
        public ViewerForm1()
        {
            InitializeComponent();
        }

        private void btnSelectPicture_Click(object sender, EventArgs e)
        {
            //show the open file dialog box
            if(ofdSelectPicture.ShowDialog()==DialogResult.OK )
            {
                //load the picture into the picture box.
                picShowPicture .Image =Image .FromFile(ofdSelectPicture.FileName);
                //show the name of the file in the form's caption.
                this .Text=string .Concat("Picture View("+ofdSelectPicture.FileName+")");
            }
        }
    }

        private void btnQuit_Click(object sender, EventArgs e)
        {
            //close the window and the application
            this .Close();
        }
}

警告    1    文件“D:\新建文件夹 (1)\WindowsFormsApplication3\WindowsFormsApplication3\ViewerForm.cs”不支持代码分析或生成,因为它未包含在支持代码的项目中。        0    0   

错误    2    应输入 class、delegate、enum、interface 或 struct    D:\新建文件夹 (1)\WindowsFormsApplication4\WindowsFormsApplication4\ViewerForm1.cs    32    17    WindowsFormsApplication4
4 回复
#2
wyc1992882014-02-26 14:36
private void btnQuit_Click(object sender, EventArgs e)
这个按钮事件应该放在你的ViewerForm1类里,不能放在类外。
#3
wangnannan2014-02-27 08:59
方法必须包含在类里 作用域问题不解释
#4
做好每一天2014-02-27 16:08
namespace WindowsFormsApplication4
 {
     public partial class ViewerForm1 : Form
     {
         public ViewerForm1()
         {
             InitializeComponent();
         }
         private void btnSelectPicture_Click(object sender, EventArgs e)
         {
             //show the open file dialog box
             if(ofdSelectPicture.ShowDialog()==DialogResult.OK )
             {
                 //load the picture into the picture box.
                 picShowPicture .Image =Image .FromFile(ofdSelectPicture.FileName);
                 //show the name of the file in the form's caption.
                 this .Text=string .Concat("Picture View("+ofdSelectPicture.FileName+")");
             }
         }
        private void btnQuit_Click(object sender, EventArgs e)
         {
             //close the window and the application
             this .Close();
         }
     }         
 }
这样就对了。。。。。
#5
做好每一天2014-02-27 16:08
namespace WindowsFormsApplication4
 {
     public partial class ViewerForm1 : Form
     {
         public ViewerForm1()
         {
             InitializeComponent();
         }
         private void btnSelectPicture_Click(object sender, EventArgs e)
         {
             //show the open file dialog box
             if(ofdSelectPicture.ShowDialog()==DialogResult.OK )
             {
                 //load the picture into the picture box.
                 picShowPicture .Image =Image .FromFile(ofdSelectPicture.FileName);
                 //show the name of the file in the form's caption.
                 this .Text=string .Concat("Picture View("+ofdSelectPicture.FileName+")");
             }
         }
        private void btnQuit_Click(object sender, EventArgs e)
         {
             //close the window and the application
             this .Close();
         }
     }         
 }
这样就对了。。。。。
1