如何使用ListBox放置Windows窗体对象/工具?

时间:2016-03-07 19:00:17

标签: c# wpf listbox

好吧,我真的不知道怎么说这个问题,但这就是我的意思:

我正在Windows Visual Studio上创建一个C#应用程序。用户可以从表单左侧的ListBox中选择一个项目,并在右侧显示相应的信息。 ListBox中的每个项目都会在右侧显示不同的图像,按钮,标签等组合。

当使用Windows窗体的设计器时,会显示每个对象(按钮,标签),这使得很难为ListBox上的每个项目放置不同的对象。我到了那么多的按钮,标签,彼此重叠,我无法妥善放置我的物品。

我该如何解决这个问题?我应该使用某种控制吗?

编辑:以下是我目前正在做的一个例子:

 if ((string)choiceBox.SelectedItem == "Home")
        {
            thatLabel.Visible = true;
            someLabel.Visible = true;
            anotherLogo.Visible = true;
            madeLabel.Visible = true;

            basiclabel3.Visible = false;
            basiclabel2.Visible = false;
            basiclabel1.Visible = false;
            externalipLabel.Visible = false;
            ipLabel.Visible = false;
            computernameLabel.Visible = false;
        }
        else if ((string)choiceBox.SelectedItem == "Basic Details")
        {
            string hostName = Dns.GetHostName();
            string ip = Dns.GetHostByName(hostName).AddressList[0].ToString();


            string extIP;
            using (WebClient wc = new WebClient())
            {
                extIP = wc.DownloadString("http://icanhazip.com/");
            }

            if (!string.IsNullOrEmpty(extIP))
            {
                externalipLabel.Text = extIP.ToString();
                externalipLabel.Visible = true;
            }   
            ipLabel.Text = ip.ToString();
            ipLabel.Visible = true;
            computernameLabel.Text = hostName.ToString();
            computernameLabel.Visible = true;
            basiclabel1.Visible = true;
            basiclabel2.Visible = true;
            basiclabel3.Visible = true;

            thatLabel.Visible = false;
            someLabel.Visible = false;
            anotherLabel.Visible = false;
            madeLabel.Visible = false;
        } 
    }

0 个答案:

没有答案