首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

这个小程序为什么输出和书下写的不一样呢

2012-09-22 
这个小程序为什么输出和书上写的不一样呢?程序是C#入门经典上的例子程序.创建一个winform程序代码是C# cod

这个小程序为什么输出和书上写的不一样呢?
程序是C#入门经典上的例子程序.创建一个winform程序代码是

C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Ch08Ex01{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            ((Button)sender).Text = "Clicked!";            Button newButton = new Button();            newButton.Text = "New Button!";            newButton.Click += new EventHandler(newButton_Click);            Controls.Add(newButton);        }        private void newButton_Click(object sender, System.EventArgs e)        {            ((Button)sender).Text = "Clicked!!";        }    }}

为什么最后输出的时候,右上角本应该显示New Button后来只显示了一个New呢?

[解决办法]
如果是动态创建的控件,是不能在前台修改的。所以这些必须在后台代码中设置。其实你去点newButton.时候就可以看到很多属性了,只是对里面的属性还不是很属性,不知道他们的作用。多做做就知道了。

热点排行