我想同时关掉几张表格。 当我运行它时,当我选择“case 1”时它仍会显示所有表单。 这一切的意义在于选择他想要看多少“跟踪栏”。默认情况下它是10,这取决于他选择了多少。让我说他选择6.所以我把轨迹栏7-10放在假,同样的文本框和图片框。 抱歉我的英文不好,希望大家都明白我的问题,谢谢你的阅读!
namespace project
{
public partial class Form2 : Form
{
public Form2(int sliders)
{
InitializeComponent();
string[,] test = new string[10, 4] {{"trackBar1.visible = false;", "textbox1,visible = false;", "textbox11.visible = false;", "picturebox2.visisble = false;"},
{"trackBar2.visible = false;", "textbox2,visible = false;", "textbox12.visible = false;", "picturebox3.visisble = false;"},
{"trackBar3.visible = false;", "textbox3,visible = false;", "textbox13.visible = false;", "picturebox4.visisble = false;"},
{"trackBar4.visible = false;", "textbox4,visible = false;", "textbox14.visible = false;", "picturebox5.visisble = false;"},
{"trackBar5.visible = false;", "textbox5,visible = false;", "textbox15.visible = false;", "picturebox6.visisble = false;"},
{"trackBar6.visible = false;", "textbox6,visible = false;", "textbox16.visible = false;", "picturebox7.visisble = false;"},
{"trackBar7.visible = false;", "textbox7,visible = false;", "textbox17.visible = false;", "picturebox8.visisble = false;"},
{"trackBar8.visible = false;", "textbox8,visible = false;", "textbox18.visible = false;", "picturebox9.visisble = false;"},
{"trackBar9.visible = false;", "textbox9,visible = false;", "textbox19.visible = false;", "picturebox10.visisble = false;"},
{"trackBar10.visible = false;", "textbox10,visible = false;", "textbox20.visible = false;", "picturebox11.visisble = false;"}};
switch (sliders)
{
case 1:
foreach (string item in test)
Console.WriteLine(item);
Console.ReadLine();
break;
}
}
}
}
答案 0 :(得分:0)
您可以创建一个轨迹栏或文本框控件数组,并对其进行迭代以设置可见性。否则你将不得不使用反射来从字符串中获得控制权。
我建议不要使用字符串,更好地使用类型集合。