Harikrishna
Harikrishna

Reputation: 4305

Altering the view of form only by clicking on the button

Is there any code like, frmBallloon is shown in btnShow click event of the frmBase and again I want to show frmBase if user clicks on the btnShow of the frmBalloon then there is two copy of the frmBase.I want only one copy.Then how can I alter the form view by clicking on the button.

Upvotes: 0

Views: 125

Answers (2)

Adriaan Stander
Adriaan Stander

Reputation: 166396

You can try something like this

Code for Form1

public Form2 f2;
private void button1_Click(object sender, EventArgs e)
{
    if (f2 == null)
    {
        f2 = new Form2 {f1 = this};
        f2.Show();
    }
    else
        f2.Focus();
}

Code for Form2

public Form1 f1;
private void button1_Click(object sender, EventArgs e)
{
    if (f1 == null)
    {
        f1 = new Form1 {f = this};
        f1.Show();
    }
    else
        f1.Focus();
}

Upvotes: 1

Anuraj
Anuraj

Reputation: 19598

Try this

frmBase button click

Form2 frm2 = new Form2();
this.Visible = false;
frm2.Show(this);

And here frmBalloon Button Click

if (this.Owner != null)
{
this.Visible = false;
this.Owner.Show();
}

Upvotes: 1

Related Questions