C# lesson1
窗体
- 修改标题:属性里修改,Text
- 修改图标 :窗口样式,Icon 32*32大小最合适
- GrowAndShrink:不允许修改窗体大小
public Form1()
{
InitializeComponent();//进行初始化的过程
this.Load += 窗体_load; //覆盖了初始化,加载窗体_load
}
private void 窗体_load(object sender, EventArgs e)
{
this.Text = "这是代码绑定标题";
}
private void Form1_Load(object sender, EventArgs e)// InitializeComponent()后自动加载
{
//窗体第一次被初始化,是否允许最大化、标题、大小等
this.Text = "这是标题";
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//在这执行清理
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
int w = this.Width;
int h = this.Height;
this.Text = String.Format( "当前窗体宽度:{0},高度:{1}", w,h);
}
}
按钮
- 基本特性:鼠标滑过和点击,背景颜色会改变
- 控件都有enable属性,控制是否让用户使用
- MouseClick和Click:
- 共同点:都接受鼠标左键的单击事件,并且具有共同信息(鼠标单击的位置(x/y坐标),坐标按下的键,按下次数)
- 不同点:MouseClick会接受鼠标其他按键,click不会。(button比较特殊,只接受左键)
private void button1_Click(object sender, EventArgs e)
{
this.Text = "按钮1的click事件";
button2.Enabled = false; //能否被用户使用
}
private void button2_Click(object sender, EventArgs e)
{
this.Text = "按钮2的click事件";
button1.Enabled = false;
}
private void button3_Click(object sender, EventArgs e)
{
button2.Enabled = true;
button1.Enabled = true;
}
private void button4_MouseClick(object sender, MouseEventArgs e)
{
this.Text = "按钮4被点击";
}
private void button2_Leave(object sender, EventArgs e) //离开这个按钮,不是焦点
{
button3.BackColor = Color.Red;
}