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:)

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

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:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.