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 8720807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:07:01+00:00 2026-06-13T07:07:01+00:00

Basically; Form1 has 2 buttons, Form2 has 1 button. When you click Form2’s button

  • 0

Basically; Form1 has 2 buttons, Form2 has 1 button.
When you click Form2’s button it checks which button on Form1 you clicked, opening Form3 or Form4 depending on which button you clicked (on Form1).


So I’ve utilized Mark Halls first method of passing variables between forms. Now for the second half of my closed refinement.

Form1

private void btnLogin_Click(object sender, EventArgs e)
        {
            // Call function while storing variable info.
            Account("login");
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            // Call function while storing variable info.
            Account("register");
        }

        // Function used to pass Variable info to Account form while opening it as instance.
        private void Account(string formtype)
        {
            // Generate/Name new instant of form.
            frontend_account frmAcc = new frontend_account();
            // Pass variable to instance.
            frmAcc.CheckButtonClick = formtype;
            // Show form instance.
            frmAcc.Show(this);
            // Hide this instance.
            this.Hide();
        }

Form2

// String Variable to store value from Login.
        public string CheckButtonClick { get; set; }

        private void btnContinue_Click(object sender, EventArgs e)
        {
            // If statement to open either Main form or Registration form, based on Login variable.
            if (CheckButtonClick == "login")
            {
                // Generate/Name new instant of form.
                frontend_main frmMain = new frontend_main();
                // Show form instant.
                frmMain.Show();
                // Close this instant.
                this.Close();
            }
            else if (CheckButtonClick == "register")
            {
                // Generate/Name new instant of form.
                frontend_register frmReg = new frontend_register();
                //  Show form instant.
                frmReg.Show();
                // Close this instant.
                this.Close();
            }
        }

On Form2 there are TWO radio buttons, can I adept that code to set the focus of a tab control when a form is opened? ie. if radClient is checked set focus on tabcontrol after opening winform, else if radStudent is checked set focus on tabcontrol (other page) after opening winform… and i guess don’t open a winform if no radio is checked.

I believe this will set the focus;

// Sets focus to first tab.
tabRegister.SelectedTab = tabRegister.TabPages[0];
// Sets focus to second tab.
tabRegister.SelectedTab = tabRegister.TabPages[1];
  • 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-06-13T07:07:02+00:00Added an answer on June 13, 2026 at 7:07 am

    In your example the first problem I see is you are closing your parent form which closes your Form1 and disposes of Your Form2, What I would do is Hide Form1 instead of Closing it, I would then create a public property on Form2 to pass in the Button that was selected. But anytime you are opening and closing multiple Forms it can get messy, what I would do would be to create UserControls for your additional Forms and swap them out in a Panel. The first example is how to do it the way that you asked.

    Form

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        private void btnLogin_Click(object sender, EventArgs e)
        {
            ShowForm2("login");
        }
    
        private void btnRegister_Click(object sender, EventArgs e)
        {
            ShowForm2("register");
        } 
    
    
        private void ShowForm2(string formtype)
        {
            Form2 f2 = new Form2(); // Instantiate a Form2 object.
            f2.CheckButtonClick = formtype;
            f2.Show(this); // Show Form2 and  
            this.Hide(); // closes the Form1 instance.  
    
        }
    }
    

    Form2

    ublic partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
    
        public string CheckButtonClick { get; set; }
    
        private void button1_Click(object sender, EventArgs e)
        {
            if (CheckButtonClick == "login")
            {
                Form3 f3 = new Form3(); // Instantiate a Form3 object.  
                f3.Show(); // Show Form3 and  
                this.Close(); // closes the Form2 instance.  
            }
            else if (CheckButtonClick == "register")
            {
                Form4 f4 = new Form4(); // Instantiate a Form4 object.  
                f4.Show(); // Show Form4 and  
                this.Close(); // closes the Form2 instance.  
            } 
    
        }
    }
    

    Form3 and Form4 note since Form1 is long forgotten to these forms I search for it to Open back up

    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
    
        private void Form3_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormCollection frms = Application.OpenForms;
            foreach (Form f in frms)
            {
                if (f.Name == "Form1")
                {
                    f.Show();
                    break;
                }
            }
        }
    }
    

    The second Option with UserControls has one Form with a Panel on it. It uses events to signal the Form to Change Controls plus a public property on UserControl2

    public partial class Form1 : Form
    {
        string logonType;
        public Form1()
        {
            InitializeComponent();
        }
    
        private void userControl1_LoginOrRegisterEvent(object sender, LoginOrRegisterArgs e)
        {
            logonType = e.Value;
            userControl2.BringToFront();
        }
    
    
        private void userControl2_ControlFinshedEvent(object sender, EventArgs e)
        {
            if (logonType == "logon")
                userControl3.BringToFront();
            else if (logonType == "register")
                userControl4.BringToFront();
        }
    
        private void userControl3_ControlFinshedEvent(object sender, EventArgs e)
        {
            userControl1.BringToFront();
        }
    
        private void userControl4_ControlFinshedEvent(object sender, EventArgs e)
        {
            userControl1.BringToFront();
        }
    }
    

    UserControl1

    public partial class UserControl1 : UserControl
    {
       public delegate void LoginOrRegisterHandler(object sender, LoginOrRegisterArgs e);
       public event LoginOrRegisterHandler LoginOrRegisterEvent;
    
        public UserControl1()
        {
            InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            LoginOrRegisterArgs ea = new LoginOrRegisterArgs("logon");
            LoginOrRegisterEvent(sender, ea);
        }
    
        private void button2_Click(object sender, EventArgs e)
        {
            LoginOrRegisterArgs ea = new LoginOrRegisterArgs("register");
            LoginOrRegisterEvent(sender, ea);
        }
    }
    
    public class LoginOrRegisterArgs
    {
        public LoginOrRegisterArgs(string s) {Value = s;}
        public string Value {get; private set;}
    }
    

    UserControl2

    public partial class UserControl2 : UserControl
    {
        public delegate void ControlFinishedHandler(object sender, EventArgs e);
        public event ControlFinishedHandler ControlFinshedEvent;
        public UserControl2()
        {
            InitializeComponent();
        }
        public string SetLogonType { get; set; }
    
        private void button1_Click(object sender, EventArgs e)
        {
            ControlFinshedEvent(sender, new EventArgs());
        }
    }
    

    UserControl3 & UserControl4 exactly the same except for different Class Name

    public partial class UserControl3 : UserControl
    {
        public delegate void ControlFinishedHandler(object sender, EventArgs e);
        public event ControlFinishedHandler ControlFinshedEvent;
        public UserControl3()
        {
            InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            ControlFinshedEvent(sender, new EventArgs());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this thread which basically has the same issue I have. But their
basically i have to pages like test.aspx and test1.aspx. test.aspx has one button and
I have a main class(which is basically a netbeans form;drag and drop) from where
Basically I've made a form in Cakephp 2.1 with a jQuery button that appends
My site has a form which insert records in a database using ajax, at
I am working on a search function on RoR that basically just has a
So, I have a form (which is basically a UITableView), and once I finish
I need to access a .net application which has no public COM or API.
I'm wanting to click a button and have the matching id name show. I
I have two web pages which work basically the same, code-wise, but one of

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.