我想将表单放在数组中,但这并不顺利



我想同时关闭几个表单。当我运行它时,当我选择"案例 1"时,它仍然显示所有表单。这一切的意义是选择他想看到的"多少轨道栏"。默认情况下是 10,这取决于他选择多少。假设他选择 6。所以我把跟踪栏 7-10 放在 false 上,与文本框和图片框相同。对不起,我的英语不好,希望大家理解我的问题,谢谢阅读!

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;
} 
}
}
}

您可以创建跟踪栏或文本框控件的数组,并循环访问它们以设置可见性。 否则,您必须使用反射来从字符串中获取控制权。

我建议不要使用字符串,最好使用类型化集合。

相关内容

  • 没有找到相关文章

最新更新