Passing Data in MDI Parent form and Child Form

S

Saimvp

Hi and Hello.
Im new at .net framework. Now Im using C# . I have a little problem.
How can I get a value of a text in the mdi parent form to child form.

Example in VB6:

form1.text1.text = MainForm.text1.text

How to convert it to C#
 
M

Marc Gravell

The best approach is to create a public (or internal) property that
exposes this, and access the text through the property - i.e.

## in Form1.cs ##

public string CaptionText {
get {return text1.Text;}
set {text1.Text = value;}
}

## in parent ## (where form1 is an instance of Form1)

form1.CaptionText = "abc";

## end ##

That way, the UI details are properly encapsulated inside Form1.

Marc
 
F

Family Tree Mike

As far as I know, an MDI container (MainForm) cannot have a control within
it, only MDI children. In general though, you could have code in your Shown
or Load event handlers with in the form1 form that look like this:

Text1.Text = ((MainForm) ParentForm).Text1.Text;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top