Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All

Requirement - I have two page in my app containg button in each so that when i click the button of first page it will switch me to second page and when click on the button on second page it will switch me to first page.

Problem - When i click the button of first page it will switch me to second page but when i click on the button of second page instead of switching to second page it will open the new instance of second page so that two instance of first page is opened.

So that multiple instance of same page is opened. I hope this time i am clear.

Please help me out.

Regards
Sunny

What I have tried:

C#
private void Btn(object sender, RoutedEventArgs e)
        {


               if (btn!= null)
                {
                  btn.Topmost = true;
                }

                else
                {
                  btn = new btn("abc_717.xml");
                  btn.Show();
                }
        }
Posted
Updated 1-Jan-17 23:18pm
Comments
Snesh Prajapati 23-Dec-16 4:14am    
What is the framework: ASP.NET WebForm or WPF or WinForms ?

1 solution

I create a Sample Application in Winforms:-
Here Form3 is a MDI Form, My code is:
MDI Form:
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        Form1 frm1;
        Form2 frm2;
        public Form3()
        {
            InitializeComponent();
            frm1 = new Form1();
            frm2 = new Form2();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            frm1.MdiParent = this;
            frm2.MdiParent = this;
            frm1.Show();
        }
        public void showFirst()
        {
            frm1.Show();
            frm1.Focus();
        }
        public void showSecond() {
            frm2.Show();
            frm2.Focus();
        }
    }
}

Form1(which also First Form) Code:-
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ((Form3)this.MdiParent).showSecond();
        }
       
    }
}


Form2(which is Second form) code:
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ((Form3)this.MdiParent).showFirst();
        }
    }
}


I Hope this sample will help you..
If you have any issue then feel free to ask... :-)
 
Share this answer
 

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