Windows Develop Bookmark and Share   
 index > Windows Forms General > want 2 share data from 1 from 2 another with MDIFORM
 

want 2 share data from 1 from 2 another with MDIFORM

in C# .NET

i got a MDIForm who has a childform (Form1). Form1 has a button who calls to another new childform( Form2)in ShowDialog way. the Form2 Has a TextBox and a Button. I want to Write in The Form2's Textbox and then click the Form2's Submit Button and the Form2's TextBox.text goto the Form1.Text...

its jst mean dat i want 2 share some data from 1 form 2 another so dat its can be use by any form....(IN C#.NET)


PraveenRockz  Wednesday, January 02, 2008 5:14 AM

Hi PraveenRockz,

You can expose some properties in the Form1, so you can use these properties to change the field inside the Form1. Then you need you add a reference to Form1 in Form2. Try something like the following:

The code for Form1

Code Block

public partial class Form1 : Form

public Form1()

public string MyText

set { this.textBox1.Text = value; }

private void button1_Click(object sender, EventArgs e)

Form2 f = new Form2(this);

this);

The code for Form2

Code Block

public partial class Form2 : Form

public Form2(Form1 f)

Form1 internalform;

private void btnSubmit_Click(object sender, EventArgs e)

if (internalform != null)

this.textBox1.Text;

this.Close();

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Friday, January 04, 2008 3:16 AM

Where have you heard that C# doesn't support global variable? It does support, it just has a different name.

You can declar a static variable on your Program.cs file.

Something like this:

Code Block

class Program

{

public static string myString;

.

.

.

.

}

And you access/change it through Program.myString

This values for any kind of variable you might want to declare.

Regards,

Fábio

Fábio Franco  Thursday, January 10, 2008 12:26 PM

Hi PraveenRockz,

You can expose some properties in the Form1, so you can use these properties to change the field inside the Form1. Then you need you add a reference to Form1 in Form2. Try something like the following:

The code for Form1

Code Block

public partial class Form1 : Form

public Form1()

public string MyText

set { this.textBox1.Text = value; }

private void button1_Click(object sender, EventArgs e)

Form2 f = new Form2(this);

this);

The code for Form2

Code Block

public partial class Form2 : Form

public Form2(Form1 f)

Form1 internalform;

private void btnSubmit_Click(object sender, EventArgs e)

if (internalform != null)

this.textBox1.Text;

this.Close();

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Friday, January 04, 2008 3:16 AM

sir this code is not working.......

i m facing problem while using this code...

PraveenRockz  Thursday, January 10, 2008 12:01 PM

And the problem is???

Fábio Franco  Thursday, January 10, 2008 12:03 PM

sir acctually i want 2 check in MDI parent form that if d form2 which is CHILD form of Form1(PARENT FORM)

is OPEN den d message get display dat d "form is already open " or its Not den form2 get open..

for eg:-

there is one MDI form Called "Customer detail"

in file menu der is One Sub menu Called "New detail" ( which is form2)

wen d user click on file-->New details

den d "New Detail "(form2 get Open)

but if it is already open it display one message dat form is already open.

and i m trying all this In C sharp.. and as i kno ..cshap doesnt support global variable..

sir I will be very thankfull to u if u can solve my problem.

PraveenRockz  Thursday, January 10, 2008 12:21 PM

Where have you heard that C# doesn't support global variable? It does support, it just has a different name.

You can declar a static variable on your Program.cs file.

Something like this:

Code Block

class Program

{

public static string myString;

.

.

.

.

}

And you access/change it through Program.myString

This values for any kind of variable you might want to declare.

Regards,

Fábio

Fábio Franco  Thursday, January 10, 2008 12:26 PM

thankz sir its really working .. thankz a lot...

PraveenRockz  Thursday, March 13, 2008 4:14 AM

You can use google to search for other answers

Custom Search

More Threads

• Datagridview row validatinq event & focus
• Custom List type widget
• Focus problem in WinForms app updating interface on a timer
• Path related query
• Problem with compiling in English and German VS 2005
• Visual C# forms - Table with check boxes
• printing in order
• Callback Application Needs To Have Top Most Dialog
• Change Mouse Cursor Position on Picturebox.
• Issues with MyApp.exe.config