C#動態創建button按鈕的方法實例詳解。本站提示廣大學習愛好者:(C#動態創建button按鈕的方法實例詳解)文章只能為提供參考,不一定能成為您想要的結果。以下是C#動態創建button按鈕的方法實例詳解正文
投稿:lqh
這篇文章主要介紹了C#動態創建button按鈕的方法實例詳解的相關資料,需要的朋友可以參考下C#動態創建button按鈕的方法實例詳解
C#編程中經常需要動態創建,本文主要介紹C#動態創建button按鈕的方法,涉及C#按鈕屬性動態設置的相關技巧,以供借鑒參考。具體實現方法如下:
例子:
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;
using System.Reflection;
namespace App
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
System.Windows.Forms.Button button = new Button();
button.Text = "按鈕";
button.Size = new Size(100, 30);
button.Location = new Point(0, 0);
button.Click += delegate
{
ButtonClick();
};
this.Controls.Add(button);
}
void ButtonClick()
{
MessageBox.Show("點擊了click事件");
}
}
}
//注意:主要是看事件
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!