在C#中添加动态按钮 [英] Adding dynamic button in c#

查看:271
本文介绍了在C#中添加动态按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我看不到我的按钮?

Why cant i see my button?

int intnum = Convert.ToInt16(textBox1.Text);
Button[,] cal=new Button[intnum, intnum];
this.Controls.Add(cal[1, 1]);





我做到了这一点:


c#添加动态按钮 [





I did this one:


c# adding dynamic button[^]


still got an error.

推荐答案

Button[,] cal = new Button[intnum, intnum];
Button b11 = cal[1, 1]; // b11 is null
Button newbtn = new Button(); // create new button 
newbtn.Text = "test";
cal[1, 1] = newbtn; //and assign it to 1, 1
this.Controls.Add(cal[1, 1]); // now you can see the button in UI


因为没有将控件添加到任何容器中.将其添加到表单中已定义的占位符面板中.给它一个出现的位置/位置.

更新:
您尚未创建按钮.首先创建它们,然后将其添加到容器中以进行显示.
Because you did not add the control to any container. Add it to a defined placeholder, panel in your form. Give it a place/location to appear.

UPDATE:
You have not created buttons. Create them first and then add it to the container for display.


这篇关于在C#中添加动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆