简体   繁体   English

如何以面板形式访问控件

[英]How to access to a control in a form that lives in a panel

I have a panel named panel1, two buttons named buttonLoad and buttonSave. 我有一个名为panel1的面板,两个名为buttonLoad和buttonSave的按钮。 All of these controls live in Form1. 所有这些控件都位于Form1中。

There's another Form(Form2) which consist of a textbox named textbox1. 还有另一个Form(Form2),它包含一个名为textbox1的文本框。

when the buttonLoad is clicked, the Form2 is loaded into the panel1. 单击buttonLoad时,将Form2加载到panel1中。

After typing something in the textbox1 when I click the save button how can i get the text that was typed? 当我单击保存按钮在textbox1中键入内容后,如何获取输入的文本? ( I want to know how to get the textbox1.text which is in Form2 loaded to panel1) (我想知道如何将Form2中的textbox1.text加载到panel1上)

It would be easier to nail down with a code sample but from the description it sounds like you have a control within a form that you would like to access. 确定代码示例会更容易,但是从描述中看来,您似乎想在要访问的表单中包含一个控件。

If the form is in a separate file, say an ascx that you place onto the page, then you will need to make sure the textbox control within that form is declared public, or you might need to make a publicly accessible variable within the ascx file that grabs the value out of the textbox. 如果表单在单独的文件中,比如说您要放置在页面上的ascx,则需要确保该表单中的文本框控件已声明为public,或者您可能需要在ascx文件中设置可公开访问的变量从文本框中获取值。

It might be something like 可能是这样的

Form2 myForm = new Form2();
string val = myForm.textbox1.Text;

if your textbox is publicly accessible or 如果您的文本框可公开访问,或者

Form2 myForm = new Form2();
string val = myForm.MyAccessorVarForTextBox1;

if you use a public variable that accesses a private textbox. 如果您使用访问私有文本框的公共变量。

Hope this gives you something to start with. 希望这能给您一些开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM