954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with GUI. Updating between 2 forms.

Hie guys,

Im creating a program that will display the details of every state of India when user will click on that states button.

I have two forms:
Main.cs = MdiParent form for program.
India.cs = Where map of India will be displayed including buttons of every state.

So what i want is... When user click on "Punjab"(A state of India) button in India.cs form then label1.text should change to "Punjab" in Main.cs form.

I can do it easily if both things on same form. but in this case, I have two different forms.

Can anyone please help me out to solve this matter.

Thanks In Advance.
PK:)

puneetkay
Junior Poster
122 posts since Nov 2007
Reputation Points: 51
Solved Threads: 24
 

There are a number of approaches, but the easiest way would be to just pass the Main.cs label1 object to the second form, and let the buttons set its text.

Add the label as a parameter to the contructor.

India india = new India(label1);
.....


In the India.cs file setup the constructor and a variable

private Label mainLabel = null;

public India( Label mainLabel )
{
   this. mainLabel = mainLabel;
...
}

private void onSomeButtonClick(object sender, EventArgs e)
{
     Button myBtn = (Button)sender;
     mainLabel.Text = myBtn.Text;
....
}


Just typed this off the top of my head, so you may have to play with it, but I think you get the idea.

// Jerry

JerryShaw
Posting Pro in Training
465 posts since Nov 2006
Reputation Points: 69
Solved Threads: 75
 

Hie Jerry,

Thanks for reply and helping me.

Actually, your code didnt help me that much but thanks for the idea! Its working now :)

Regards,
PK:)

puneetkay
Junior Poster
122 posts since Nov 2007
Reputation Points: 51
Solved Threads: 24
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You