VS2019 C# Windows From
//
private void button2_Click(object sender, EventArgs e)
{
addButton(this, "hello1",100,100,50,50);
addButton(tabPage1, "hello2", 0, 100, 50, 50);
addButton(tabPage2, "hello3", 0, 100, 50, 50);
}
// ==========================================================
private void addButton(Control a , string butText , int x , int y , int width , int Height)
{
Button Obj_Button = new Button();
Obj_Button.FlatStyle = FlatStyle.Standard;
Obj_Button.BackColor = Color.FromArgb(200, 250, 250);
Obj_Button.ForeColor = Color.Black;
Obj_Button.UseVisualStyleBackColor = true;
Obj_Button.Height = Height;
Obj_Button.Width = width;
Obj_Button.Location = new Point(x, y);
Obj_Button.Visible = true;
Obj_Button.Name = butText;
Obj_Button.Text = butText;
Obj_Button.Tag = butText;
Obj_Button.TextAlign = ContentAlignment.MiddleLeft;
Obj_Button.Click += new EventHandler(Buttons_Click);
a.Controls.Add(Obj_Button);
}
// ===== 新增事件 =======================
void Buttons_Click(object sender, EventArgs e)
{
this.Text = (sender as Button).Text;
}
沒有留言:
張貼留言