1、文本编辑器显示多行
textBox1.Multiline = true;
2、子窗体显示成多个数据页面
级联this.LayoutMdi(MdiLayout.Cascade);
水平平铺this.LayoutMdi(MdiLayout.TileHorizontal);
数值平铺this.LayoutMdi(MdiLayout.TileVertical);
3、在子窗体中找到当前激活的窗体
this.ActiveMdiChild;
Form2 frm = (Form2)this.ActiveMdiChild;//强制转换成Form2
4、Delegate回调
从 InitializeComponent()中,屏蔽掉//this.button2.Click += new System.EventHandler
(this.button2_Click);
private void button1_Click(object sender, EventArgs e)
{
this.button2.Click += new EventHandler(button2_Click);
//给button2的单击添加方法button2_Click,-=为去掉方法button2_Click
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("I am button2");
}
5、验证textbox是否为空
在form1中添加一个textbox1,button1,errorProvider1
给textbox1的Validated事件添加代码
private void textBox1_Validated(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("textBox1的内容为空,请输入");
}
}
在form1的InitializeComponent()中,找到button1,用+=给button1的click单击事件添加方法
textBox1_Validated。