本文介绍了从新形式中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户使用一个按钮来启动一个新窗口并获得我想要使用的新值。


新值不是已更新为form1。


        private void button1_Click(object sender,EventArgs e)

        {
$


            Form2 newForm = new Form2();
$


            newForm.Show();

            portname2 = newForm.portname;



 

                         

        }



newform有一个列表框我想使用值


        public string portname; //全局变量



       private void listBox1_SelectedIndexChanged(object sender,EventArgs e)

        {

           

           portname = listBox1.SelectedItem.ToString();

           Thread.Sleep(500);

           MessageBox.Show(" new com port" + portname);

           

     

            this.Close();

        }



如何更新原始表单以便更改portname2




解决方案

I am trying to get the user to with a button to launch a new window and get a new value that i want to use.

The new value is not being updated to form1.

        private void button1_Click(object sender, EventArgs e)
        {

            Form2 newForm = new Form2();

            newForm.Show();
            portname2 = newForm.portname;

 
                        
        }

newform has a listbox i want to use the value

        public string portname ;//global variable

       private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
           
           portname = listBox1.SelectedItem.ToString();
           Thread.Sleep(500);
           MessageBox.Show("new com port " + portname);
           
     
            this.Close();
        }

How do i update original form so portname2 is changed

解决方案


这篇关于从新形式中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 15:38