weixin_44097963
2019-04-29 23:53
采纳率: 66.7%
浏览 409

如何调用listbox中某行的内容给label 和 button,同时是两边数值是同步的?c# winform

listbox中调取某行(例如第三行)的内容给另一个窗体(非子窗体)的button 和label,同时修改了listbox那行内容,button和label同步改变?并且如果该值被删除了,button和label内容也被删除。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • weixin_44097963 2019-06-26 00:59
    已采纳

    label form代码
    public AddRenameWindow addrename { get; set; }
    //connect with addrename form 's data

        public void AlterWindow_Load(object sender, EventArgs e)
        {
            //show  teams' name in addrenmae form on this form 
            label4.Text = AddRenameWindow.a[0];
            label5.Text = AddRenameWindow.a[1];
            label6.Text = AddRenameWindow.a[2];
            label7.Text = AddRenameWindow.a[3];
            label8.Text = AddRenameWindow.a[4];
            label9.Text = AddRenameWindow.a[5];
            label10.Text = AddRenameWindow.a[6];
            label11.Text = AddRenameWindow.a[7];
            label12.Text = AddRenameWindow.a[8];
            label13.Text = AddRenameWindow.a[9];
            label14.Text = AddRenameWindow.a[10];
            label15.Text = AddRenameWindow.a[11];
            label16.Text = AddRenameWindow.a[12];
            label17.Text = AddRenameWindow.a[13];
            label18.Text = AddRenameWindow.a[14];
            label19.Text = AddRenameWindow.a[15];
            label20.Text = AddRenameWindow.a[16];
            label21.Text = AddRenameWindow.a[17];
        }
    
    listbox form代码
            public AlterWindow alter { get; set; }
             public static string[] a = new string[30];
            public void button4_Click(object sender, EventArgs e)
            {
                AlterWindow alter = new AlterWindow();
    
                for (int index = 0; index < listBox1.Items.Count; index++)
                {
                    a[index] = Convert.ToString(listBox1.Items[index]);
                    //MessageBox.Show(a[i].ToString());
                }
                    this.Close();
                }
            }
    自己用蠢办法做出来了,虽然蠢但是同步功能完美。
    ![图片说明](https://img-ask.csdn.net/upload/201906/26/1561481978_125478.png)![图片说明](https://img-ask.csdn.net/upload/201906/26/1561481990_664584.png)
    
    
    ``
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题