码迷,mamicode.com
首页 > Windows程序 > 详细

(C#) 在程式內添加物件及事件

时间:2019-05-04 09:50:57      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:str   src   color   message   demo   dem   ima   new   bsp   

想要達成基本的GUI而不用一直重工,所以打算編輯一些方便的工具。

以button為例子之後將擴充相關的UI及知識

技术图片

 

private void Form1_Load(object sender, EventArgs e)
{
    int width, height;
    buttonTable = new Button[9];

    width = 60;
    height = 60;

    for(int i = 0; i < 9; i++)
    {
        buttonTable[i] = new Button();
        buttonTable[i].Size = new Size(width, height);
        buttonTable[i].Text = i.ToString();
        buttonTable[i].BackColor = Color.Peru;
        buttonTable[i].Click += new EventHandler(btnDemo_Click);
        this.Controls.Add(buttonTable[i]);
        if (i <= 2) buttonTable[i].Location = new System.Drawing.Point(150 + i * 60, 110);
        else if (i > 2 && i <= 5) buttonTable[i].Location = new System.Drawing.Point(150 + (i - 3) * 60, 170);
        else buttonTable[i].Location = new System.Drawing.Point(150 + (i - 6) * 60, 230);
    }
}

protected void btnDemo_Click(object sender, EventArgs e)
{
    Button temp = (Button)sender;
    MessageBox.Show(temp.Text);
}

 

(C#) 在程式內添加物件及事件

标签:str   src   color   message   demo   dem   ima   new   bsp   

原文地址:https://www.cnblogs.com/ollie-lin/p/10807286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!