Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:32:12+00:00 2026-05-31T05:32:12+00:00

I have a form with a button in it. If i click the button

  • 0

I have a form with a button in it. If i click the button another form opens. If I return to the parent form with the help of tab and click the same button again it does nothing.

Here is my code:

private void pictureBox1_Click(object sender, EventArgs e)
        {
             form wadd = new form(this);
             if ((IsFormAlreadyOpen(typeof(form))) == null)
             {
                 wadd.MdiParent = Form1.ActiveForm;
                 wadd.Show();
             }          
        }
 public static Form IsFormAlreadyOpen(Type FormType)
        {
            foreach (Form OpenForm in Application.OpenForms)
            {
                if (OpenForm.GetType() == FormType)
                    return OpenForm;
            }
            return null;
        }  



private void Form1_MdiChildActivate(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild == null)
                tabForms.Visible = false;
            // If no any child form, hide tabControl 
            else
            {
                this.ActiveMdiChild.WindowState = FormWindowState.Maximized;
                // Child form always maximized 

                // If child form is new and no has tabPage, 
                // create new tabPage 
                if (this.ActiveMdiChild.Tag == null)
                {
                    // Add a tabPage to tabControl with child 
                    // form caption 
                    TabPage tp = new TabPage(this.ActiveMdiChild.Text);
                    tp.Tag = this.ActiveMdiChild;
                    tp.Parent = tabForms;
                    tabForms.SelectedTab = tp;                                      

                    this.ActiveMdiChild.Tag = tp;
                    this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed);
                }
                else
                {

                    tab();
                }

                if (!tabForms.Visible) tabForms.Visible = true;

            }
        }
        public void tab()
        {
            for (int i = 0; i < tabForms.TabCount; i++)
            {
                if (tabForms.TabPages[i].Text == this.ActiveMdiChild.Text.ToString())
                {
                    tabForms.SelectedTab = tabForms.TabPages[i];
                    break;
                }
            }
        }

        private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
        {
            //Destroy the corresponding Tabpage when closing MDI child form
            if (tabForms.HasChildren)
            {
                ((sender as Form).Tag as TabPage).Dispose();
            }            
            //If no Tabpage left
            else if (!tabForms.HasChildren)
            {
                tabForms.Visible = false;                
            }            
        }

        private void tabForms_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((tabForms.SelectedTab != null) && (tabForms.SelectedTab.Tag != null))
                (tabForms.SelectedTab.Tag as Form).Select();            
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {            
            if (!tabForms.HasChildren)
            {
                Application.Exit();
            }            
        }

The result I want is when I click the button again the tab should gets focused to this form rather than opening new form which is not permissable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:32:14+00:00Added an answer on May 31, 2026 at 5:32 am

    I think you’d want something like this:

    public Form FormOpened<T>()
        {
            foreach (Form form in Application.OpenForms)
                if (typeof(T) == form.GetType())
                    return form;
    
            return null;
        }
    

    You could then use it like this:

    form f = (form)FormOpened<form>();
    if (f2 == null)
    {
        f2 = new form();
        f2.MdiParent = this;
        f2.Show();
    }
    else
    {
        f2.Focus();
    }
    

    Tell me if you need any help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which I want to submit upon button click which is
I have form area in my view. If I click button A , I
I have form with 1 button. when you click on the button 3 others
I currently have a simple form that when you click the save button will
I have a hidden button on a form that I need to click in
I have this form called MainForm.cs. When I click Enter The Progam button I
I have a form with a Clear button. When the user clicks Clear, I
i have a form button in the form,which i need to perform basic action
I have form with few buttons and I want to know what button is
I have a form in C# that has a button that, when clicked, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.