dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] Removing an object from a form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2017
    Location
    Nigeria
    Posts
    256

    Resolved [RESOLVED] Removing an object from a form

    I created a user control(I.e a custom control) and the control has a close button on it. I now add the control on a form. I want that when I click the close button of the control, the control should be removed from the form which it is residing just as when you click the close button on a modal form it will close the formName:  question.jpg
Views: 194
Size:  11.7 KB
    Nothing I post is Self Reliable. Use it at your own risk

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,260

    Re: Removing an object from a form

    Every container (forms, panels, groupboxes, etc) all have a Controls collection, simply remove it from the collection and it's not part of the form. Personally I would remove it from the collection and call it's Dispose() if you know you're not going to use it again.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,945

    Re: Removing an object from a form

    [Object].Dispose will remove it from the form and the form's controls collection in one line...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2017
    Location
    Nigeria
    Posts
    256

    Re: Removing an object from a form

    But do you know that that button is part of the custom control? So if you click the button, the click event will take place in the control and the parent control will not know a thing about its click event. So calling dispose method is like you are trying to tell it to dispose itself
    Nothing I post is Self Reliable. Use it at your own risk

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,945

    Re: Removing an object from a form

    Within the UserControl, calling Me.Dispose will remove it from its parent container and also from the parent container's controls collection

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width