一个简单的算法(Winform) 在Winform窗体中有50按钮,分别叫做:button_t1、button_t2~button_49、button_50,这五十按钮的初始状态是“Visible=fase”。现在要实现的功能是,“i”是一个1~50的随机数,当“i=1”的时候,button_t1显示,当“i=35”的时候button_t35显示,已经显出的按钮不必在隐藏。"i"等于几,对应的按钮就显示第几号按钮请问这样的效果应该怎样实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 什么程序要用五十个按钮来实现?你的要求很容易满足(字典或数组里查找"button_t"+i.tostring()就行了),但程序不能这样去写。 private void ShowBtn(int i){ foreach (Control ctl in this.Controls) { if (ctl is Button) { Button btn = ctl as Button; if(i==btn.Name.SubString(btnName.Length-1,2)) { btn.Visable=true; break; } else if(i==btn.Name.SubString(btnName.Length-1,1)) { btn.Visable=true; break; } } }} Button btn = this.Controls.Find("button_" + i.ToString())[0];btn.Visible = true; “ this.Controls.Find("button_t"+questions_num.ToString())[0]”这一句提示错误:错误 1 “Find”方法没有采用“1”个参数的重载C:\Users\Administrator\Desktop\CS_Colliery\CS_Colliery\CS_ExamOnline\Main.cs 174 26 CS_ExamOnline 记错了根据提示自己加一下嘛this.Controls.Find("button_t"+questions_num.ToString(), false)[0] this.Controls代表什么?是WInform中所有的控件集合吗?怎么提示“超出索引”?Button btn = (Button)this.Controls.Find("button_t" + questions_num.ToString(),false)[0]; 你的Button都加到哪个父控件里了?如果在Form上,直接用this.Controls如果在Panel里用 this.Panel1.Controls 因为用Find返回的是Control数组。如果没有找到,就会报你现在这个错误。 比如:Button btn = new Button();btn.Name = "btn1";this.Controls.Add(btn);Button btn1 = this.Controls.Find("btn1", false)[0];MessageBox.Show(btn1.Name); Form上的“GropBox”里面啊 那你就换成 this.GroupBox.Controls.Find 嘛举一反三下嘛谁是button的父控件,就用哪个的.Controls.Find fangxinggood好有耐心 我赞成 datagrid控件不练数据库,只用来显示数组中的数据怎么用? B/S架构与C/S架构的混合模式 datagridview的一个比较麻烦的问题。 各位来帮帮小弟了,呵呵... 请教Grid问题。 AjaxUploader数据绑定问题 c#中oracle表数据是一位小数的数字,为什么放进datagridview中显示就变成了两位小数呢?加了0 急需用c#来浏览大幅图像? 关于数据及更新的试验(你可能没有注意到哦!) 一个困扰了两天的问题,谁有类似经验请帮忙,急..... c#字符串问题 C#中怎么使用php的cli
private void ShowBtn(int i)
{
foreach (Control ctl in this.Controls)
{
if (ctl is Button)
{
Button btn = ctl as Button;
if(i==btn.Name.SubString(btnName.Length-1,2))
{
btn.Visable=true;
break;
}
else if(i==btn.Name.SubString(btnName.Length-1,1))
{
btn.Visable=true;
break;
} }
}}
btn.Visible = true;
“ this.Controls.Find("button_t"+questions_num.ToString())[0]”这一句提示错误:错误 1 “Find”方法没有采用“1”个参数的重载
C:\Users\Administrator\Desktop\CS_Colliery\CS_Colliery\CS_ExamOnline\Main.cs 174 26 CS_ExamOnline
this.Controls代表什么?是WInform中所有的控件集合吗?怎么提示“超出索引”?
Button btn = (Button)this.Controls.Find("button_t" + questions_num.ToString(),false)[0];
如果在Panel里用 this.Panel1.Controls 因为用Find返回的是Control数组。如果没有找到,就会报你现在这个错误。
Button btn = new Button();
btn.Name = "btn1";
this.Controls.Add(btn);Button btn1 = this.Controls.Find("btn1", false)[0];
MessageBox.Show(btn1.Name);
Form上的“GropBox”里面啊