namespace button控件
{
    public partial class Form1 : Form
    {
        private int _Counter;
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "累加器";
            this._Counter = 0;
        }        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //退出前询问是否退出
            if (MessageBox.Show("真的要退出吗?", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.No)
            {
                //取消退出
                e.Cancel = true;
            }
            
        }
        private void btnlnc_Click(object sender, EventArgs e)
        {
            this._Counter++;
            this.tbResult.Text = this._Counter.ToString("D10");
        }
    }
}很多问题..
第一: 里面有2个控件找不到 btlnc 和 tbResult ..我是按照书写的..但是怎么找都找不到书上说的那2个控件..
第二: e.Cancel = true; ..为什么这么用的..那个 e 是什么? 
第三:this.tbResult.Text = this._Counter.ToString("D10");  那个D10是什么?之前看书还有各D2..新手自学..各种不会..

解决方案 »

  1.   

    1. 打开设计视图, 拖两个控件上去.
       solution窗口, 选中Form1.cs, Shift+F72. e不就是Form1_FormClosing函数的参数么3. 将_Counter按10位十进制数输出。不足10位的前面补0
      

  2.   

    再来个代码的:
    定义两个控件变量
            Button btlnc = new Button();
            TextBox tbResult = new TextBox();
    在构造函数中执行下面的函数:
    private initCtrls()
    {
      this.Controls.Add(btlnc);
      this.Controls.Add(tbResult);
      btlnc.Location = new Point(0, 0);
      tbResult.Location = new Point(0, 100);
      btlnc.Click+=new EventHandler(btlnc_Click);
    }
      

  3.   

    你得在窗体上放置那两个按钮,你以为你抄下来就能用啊
    e.Cancel = true;是不关闭窗体
    D10这是格式化输出用的,有很多的,对于不同的类型,查阅资料吧