How to properly dispose of a custom control.

Posted on 2009-04-20
Last Modified: 2012-05-06
I have built a custom control and it works great except for one thing.  When I close the form it is on, the control is not properly disposed of, infact, if I call the form again, some the the displayed data is duplicated (due to the Load event firing again).  The form and placement of the custom control is all done at runtime.  So, I need to deal with the disposing of the control within the control itself.
Question by:David L. Hansen
    LVL 33

    Expert Comment

    LVL 9

    Expert Comment

    Also if you were opening the form by it's default instance( - instead of dim f2 as new form2) you will run into this problem.
    LVL 9

    Accepted Solution

    You need to override the dispose method, i feel you didn't google it..there's a lot of stuff which explains
    how to do this try this an example of overriding dispose method for custom controls.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now