本文介绍了将文本从动态生成的usercontrol传输到下一个表单的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows formin,其中有一个按钮1点击

按钮,用户控件在面板1上动态添加。

在该usercontrol中有4个控件

combobox1,combobox2,textbox1,textbox2

并且Windows窗体上还有4个控件,即phonemanu phonemo imietextbox和faultextbox

还有一个button2当点击按钮时,它将所有文本转移到一个新的形式,这是一个新的客户

i想要这个形式

new.phonemanu必须是(phonemanu,combobox1,combobox1等所有动态生成的组合框1)

new.phonemo必须是(phonemo,combobox2,combobox2等所有动态生成的组合框2)



i已生成此代码,但它只显示(phonemanu.text,最后生成的combobox1)

并且所有中间组合框文本都没有添加..为什么我不知道



这是我的代码



i have a windows formin which there is a button1 clicking
the button a user control is added dynamically on a panel1.
in that usercontrol there are 4 control
combobox1, combobox2, textbox1,textbox2
and there is 4 more control on the windows form which is phonemanu phonemo imietextbox and faultextbox
one more button2 when button is click it transfer
all the text to a new form which is newcustomer
i want that in this form
new.phonemanu must be (phonemanu,combobox1,combobox1,etc all the dynmaically generated combobox1)
new.phonemo must be (phonemo,combobox2,combobox2,etc all the dynmaically generated combobox2)

i have generated this code but it only shows (phonemanu.text , last generated combobox1)
and all the middle combobox text is not add.. why i dont know

this is my code

newcustomer new1 = new newcustomer();
                foreach (Control ctrl in panel1.Controls)
                {
                    if (ctrl is UserControl1)
                    {
                        UserControl1 myCrl = ctrl as UserControl1;
                        new1.phonemanu.Text = phonemanu.Text + "," + myCrl.comboBox1.Text;
                        new1.phonemo.Text = phonemo.Text + "," + myCrl.comboBox2.Text;
                        new1.imeitextbox.Text = imeitextbox.Text + "," + myCrl.textBox1.Text;
                        new1.faulttextbox.Text = faulttextbox.Text + "," + myCrl.textBox2.Text;
                        
		    }
                 }

推荐答案


这篇关于将文本从动态生成的usercontrol传输到下一个表单的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 12:55