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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:41:46+00:00 2026-06-01T07:41:46+00:00

I am new to Windows forms and having an issue handling all the user

  • 0

I am new to Windows forms and having an issue handling all the user controls. I have 3 User Controls, and when I click a accept button it takes me to the second screen (which is user control 2) but then when I click cancel on the second screen it brings me back to the first screen (I load the first user control again) the issue now is that when I click again “Accept” the welcome user control returns null and errors.

private void Viewer_Load(object sender, EventArgs e)
{
formPanel.Controls.Clear();
formPanel.Controls.Add(wel);
}

    private void SwapControls(object sender, EventArgs e)
    {
        if (formPanel.Controls.Contains(wel))
        {
            formPanel.Controls.Remove(wel);
            formPanel.Controls.Add(p);
        }
        else if (formPanel.Controls.Contains(pin) && IsAuthenticated)
        {
            formPanel.Controls.Remove(p);
            formPanel.Controls.Add(m);
        }
        else if(formPanel.Controls.Contains(pin) && !Global.IsAuthenticated)
        {
            formPanel.Controls.Remove(p);
            formPanel.Controls.Add(wel);
        }

So the first time around it loads up the welcome user control, then there I click “Accept” and it clears the User control and loads up the second one “Enter Pin Control”, from there when I click “Cancel” I remove that User Control and Load up again Welcome. BUT now, when I click Accept, I get a null in this line in the welcome user control

 this.AddControl(this, new EventArgs());

Again, I am new to windows forms and I am learning, any inputs would be much appreciated.

  • 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-01T07:41:47+00:00Added an answer on June 1, 2026 at 7:41 am

    Since you are reusing your UserControls don’t remove the handlers when you remove them from the Form, just make sure you remove them when you are finished using your UserControls.

    Try something like this.

    private void SwapControls(object sender, EventArgs e) 
    { 
        if (formPanel.Controls.Contains(wel)) 
        { 
            formPanel.Controls.Remove(wel); 
            formPanel.Controls.Add(pin); 
        } 
        else if (formPanel.Controls.Contains(pin) && Global.Instance.IsAuthenticated) 
        { 
            formPanel.Controls.Remove(pin); 
            formPanel.Controls.Add(mmenu); 
        } 
        else 
        { 
            formPanel.Controls.Remove(pin); 
            formPanel.Controls.Add(wel); 
        } 
    } 
    

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        wel.AddControl -= new EventHandler(SwapControls);
        pin.AddControl -= new EventHandler(SwapControls);
        pin.ReturnWelcome -= new EventHandler(SwapControls); 
    
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a C# .NET windows application having C# user interface and all the
I'm having an issue with a Windows Forms project. I change tabs but the
I have a Windows Forms application that I'm working on, but I'm having trouble
I am having an issue where I have a Windows CE compact framework Application
I'm having a weird issue concerning Microsoft SQL Compact Edition. In a Windows.Forms application,
I'm having an issue with a certain form in my Windows form project. Only
I have the following winforms classes: class EntityEditorForm<T>: System.Windows.Forms.Form where T: ICloneable<T> {} class
I am having trouble redirecting console output to a windows forms text box. The
I'm having a class where I'm deriving from System.Windows.Forms.Control [Serializable] public class CommonControl :
I am working on a simple windows forms paint application. I am having problem

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.