472,333 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

Is it possible to access a control in another form?


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.
Feb 2 '06 #1
10 16531

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

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.

Feb 2 '06 #2
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.
Feb 2 '06 #3
In the form that contains the Textbox, you want to do something like

public string CustomerName
get { return this.customerNameTextBox.Text; }

then from the other form you can say:


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.

Feb 2 '06 #4
Thanks Bruce,
It makes sense. I tried and fore some reason it does not return the value,
but an empty string.
Feb 2 '06 #5
My bad, I forgot SET.
Feb 3 '06 #6
Even with set it loses the value. I do not know what is wrong.
Here is the code:

In Child form:
public class Form2 : System.Windows.Forms.Form


private System.Windows.Forms.Button button1;

private System.Windows.Forms.TextBox txtContent;

private string content;


public string Content


get {return content;}

set {content = value;}



private void button1_Click(object sender, System.EventArgs e)


textBox1.Text = txtContent.Text;

this.Content = textBox1.Text;



In Main Form:

private void menuItem1_Click(object sender, System.EventArgs e)


Form2 ChildForm = new Form2();

ChildForm.MdiParent = this;



private void btnRetrieveValue_Click(object sender, System.EventArgs e)


txtDestination.Text = ChildForm.Content ;

Feb 3 '06 #7
Checkout the following FAQ - it contains an example of what you need. You will need to search for the example though, but I would bookmark this website.


Sonu Kapoor [MVP]
Posted via www.DotNetSlackers.com
Feb 3 '06 #8
Some fine tuning and it is working now.
Thanks to everybody.
Feb 3 '06 #9
Is there a particular reason why you need a "content" string field,
rather than just having the Content property read directly from the
textbox1.Text, like this:

public string Content
get { return textBox1.Text; }

Feb 3 '06 #10
No reason. I tried this way first and it did not work, then I tried
different ways to wok around.
Feb 3 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external...
by: Eric | last post by:
Is it possible to create an unbound variable in a continous form and linked with another table variable. If yes then how to declare that variable...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.