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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:37:34+00:00 2026-05-26T16:37:34+00:00

For my C# Windows Form Application, I have created a flowlayoutpanel that contains several

  • 0

For my C# Windows Form Application, I have created a flowlayoutpanel that contains several panels. Inside the panel, I have a button “Clear” for each and every single panel.

How do I write the event handler for the code for the button “Clear” such that once I have click the button, the panel would sort of be “Removed” from the flowlayoutpanel.

This is a short part of the code of the adding of panels to the flowlayoutpanel.

        nFlowPanel.Controls.Add(createNotificationPanel());
        nFlowPanel.Controls.Add(createNotificationPanel());
        nFlowPanel.Controls.Add(createNotificationPanel());
        nFlowPanel.Controls.Add(createNotificationPanelImpt());
        nFlowPanel.Controls.Add(createNotificationPanelImpt());

and this is the code for the button “Clear”

Button btnClear = new Button
        {
            Text = "Clear",
            Name = "btnClear",
            Location = new Point(416, 17)
        };
        p.Controls.Add(btnClear);
        btnClear.Click += new EventHandler(buttonClear_Click);

So what should i write in the following method to have the effect of removing e.g. the second panel that was added in the first part of code I have written?

void buttonClear_Click(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }

EDIT

the code for creating my panel is

var p = new Panel 
        {
             BorderStyle = BorderStyle.FixedSingle , 
             Size = new Size(506,100),
             Name = "notifyPanel"
        };

and the code for creating my FlowLayoutPanel is

var nFlowPanel = new FlowLayoutPanel
        {
            FlowDirection = FlowDirection.TopDown,
            WrapContents = false,
            AutoScroll = true,
            Size = new Size(530, 377),
            Location = new Point(13, 145)
        };

and the code for my button clear is

void buttonClear_Click(object sender, EventArgs e)
    {
        var button = (Control)sender;
        var panel = button.Parent.Controls["notifyPanel"];
        panel.Dispose();
    }

however it gives the error
Object reference not set to an instance of an object.
on the panel.Dispose() line.

anyone can help?

  • 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-26T16:37:35+00:00Added an answer on May 26, 2026 at 4:37 pm

    The Controls.Remove() method is very dangerous, it doesn’t dispose the control. Which will live on, moved to the so-called parking window, using up both Windows and managed resources. After a bit less than 10,000 times doing this it crashes your program when Windows is no longer willing to let you create any more windows.

    Call the control’s Dispose() method instead. That also automatically removes the control from its container.

    void buttonClear_Click(object sender, EventArgs e)
    {
        var panel = nFlowPanel.Controls["notifyPanel"];
        panel.Dispose();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# Windows Form application that contains a menu with this event:
I have created a windows form application: A presentation library with several windows forms
I have a Windows CE Form (NETCF 3.5) application that I've created via Visual
Im using c# .net windows form application. I have many databases created using sql
Im using c# .net windows application form. I have created many databases with many
I have created a fairly substantial Java GUI application with many form windows where
I have created two forms in my Windows Application. One Form acts as a
I have a windows form application that uses a Shared class to house all
Im using c# .net windows form application. I have created a database which has
Background: I have created sample windows application for learning to implement localization. My each

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.