是否可以以其他形式访问控件? [英] Is it possible to access a control in another form?
本文介绍了是否可以以其他形式访问控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MDI环境中,我处于一种形式(主要或儿童)。如何从另一种形式的文本框中访问
值?请给我一个例子。
谢谢,
Doru
Hi,
In a MDI environment I am in one form (main or child). How can access a
value from a text box placed in another form? An example please.
Thanks,
Doru
推荐答案
Doru,
您必须有对表单的引用。如果你有一个
引用,那么你必须公开一个方法/属性/字段,它将公开显示TextBox的
。一旦你这样做,你可以调用
方法/属性/字段然后做你需要做的事情。
希望这会有所帮助。
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
" Doru Roman" <做******* @ rogers.com>在消息中写道
news:%2 *************** @ TK2MSFTNGP15.phx.gbl ...
Doru,
You would have to have a reference to the form. If you have a
reference, then you have to expose a method/property/field which will expose
the TextBox publically. Once you do that, you can just call the
method/property/field and then do what you need to do with it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Doru Roman" <do*******@rogers.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
在MDI环境中,我处于一种形式(主要或儿童)。如何从另一种形式的文本框中访问
值?请给我一个例子。
谢谢,
Doru
Hi,
In a MDI environment I am in one form (main or child). How can access a
value from a text box placed in another form? An example please.
Thanks,
Doru
感谢您的回复。
我创建了表格的参考,但我不知道接下来该做什么。
你是什么意思:公开房产?
我是什么尝试将文本框的值转换为表格''的文字
属性。但我想直接获取文本框的文本属性。
Thanks for the reply.
I have created a reference of the form, but I don''t know what to do next.
What do you mean by: "to expose a property"?
What I tried was to transfer the value of the text box into the form''s Text
property. But I would like to get the textbox''s text property directly.
在包含文本框的表单中,你想要做类似
$ b的操作$ b this:
public string CustomerName
{
get {return this.customerNameTextBox.Text; }
}
然后从另一种形式你可以说:
form1.CustomerName
来获取价值。
(当然,将房产名称等更改为更多内容
对你的课程有意义。)
BTW,我不同意尼古拉斯的建议。你最有可能_don''t_
想要通过一个属性公开整个文本框,当你想要的只是内容时,这些内容可能具有一些语义含义(如
他们是客户名称,发票号码,地址或其他东西
之类的东西。公开整个文本框显示_how_您的表单是
显示/接收信息。你想要的只是信息。
In the form that contains the Textbox, you want to do something like
this:
public string CustomerName
{
get { return this.customerNameTextBox.Text; }
}
then from the other form you can say:
form1.CustomerName
to get the value.
(Of course, change the name of the property, etc., to something more
meaningful for your program.)
BTW, I disagree with Nicholas''s suggestion. You most likely _don''t_
want to expose the entire Textbox via a property when all you want is
the contents, and those contents likely have some semantic meaning (as
in they''re a customer name, an invoice number, an address, or something
like that). Exposing the entire Textbox reveals _how_ your form is
displaying / receiving information. All you want is the information.
这篇关于是否可以以其他形式访问控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文