Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ....i am fresher.... In my project i am using leftmenu with mdI form... From one mdi form to another form i am using button click to open at that time i want to pass value also...

Form1 button click:

private void button1_Click(object sender, EventArgs e)
{
Form2 objHomeForm = new Form2(textbox1.Text);
objHomeForm.Show();

leftmenu lmenuObj = (leftmenu)this.MdiParent;
lmenuObj.closeCurrentForm();
lmenuObj.frmName = "TRANSACTION\\Form2";
lmenuObj.showMyForm();
}

Form2:

public Form2(string strTextBox)
{
InitializeComponent();
textbox1.Text = strTextBox;
}


my problem is how to pass value from 1 form to another form in tis situation....plz help....
Posted
Comments
ANOOP CL NAIR 1-Feb-12 4:46am    
i try 4 ways of data passing from one form to another...still problem is not solved....plz help...how i can solve this problem...

1 solution

There are two parts here.

First, this is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Second part is this: stop torturing yourself and scare off your users! Get rid of MDI, this is a really ugly thing discouraged even by Microsoft. I can tell you what to do instead to get much nicer design options which are much easier to implement. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to Create MDI Parent Window in WPF?[^],
How to set child forms maximized, last childform minimized[^].

—SA
 
Share this answer
 
Comments
Abhinav S 1-Feb-12 3:38am    
Good links.
Sergey Alexandrovich Kryukov 1-Feb-12 3:56am    
Thank you, Abhinav. And what's most funny, most of these links are my answers, too... :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900