none
Dynamically remove a picture box from a form

    Question

  • I am adding some picture boxes to the form dynamically, I want to give the users an option to remove the picture box, say by right clicking on it and selecting Remove.
    Or by some other way, as it is avaialble in Microsoft Word, where the user can simply press Delete to remove the picture.
    How can I proceed?
    Sunday, February 28, 2010 4:11 AM

Answers

  • You can make your own context menu with features as new picture and clear pictures.

    Depending from that context menu you take actions.

    http://msdn.microsoft.com/en-us/library/aa984319(VS.71).aspx


    Success
    Cor
    • Proposed as answer by _asgar Sunday, February 28, 2010 8:39 AM
    • Marked as answer by Jeff Shan Friday, March 05, 2010 2:07 AM
    Sunday, February 28, 2010 7:42 AM
  • To add your pictureboxes you have used code such as:

      Me.Controls.Add(thisPictureBox)

    To remove a control you added, you would therefore use

      Me.Controls.Remove(thisPictureBox)

    • Marked as answer by Jeff Shan Friday, March 05, 2010 2:07 AM
    Sunday, February 28, 2010 4:15 AM
  • First of all, this is a question not discussion. You can change the thread type to question by click on change type.

    For your question, create array list of the pictureboxes that you generate dynamically so that you will be able o delete/remove it.

    Example:

    Dim DyPic as new ArrayList   or DimDyPic as New List(of PictureBox)

    So when you add new picturebox to form also add it to arraylist/List

    kaymaf

    If that what you want, take it. If not, ignored it and no complain

    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/ .

    http://www.developerfusion.com/tools/convert/csharp-to-vb/ .

    • Marked as answer by Jeff Shan Friday, March 05, 2010 2:07 AM
    Sunday, February 28, 2010 4:24 AM

All replies

  • To add your pictureboxes you have used code such as:

      Me.Controls.Add(thisPictureBox)

    To remove a control you added, you would therefore use

      Me.Controls.Remove(thisPictureBox)

    • Marked as answer by Jeff Shan Friday, March 05, 2010 2:07 AM
    Sunday, February 28, 2010 4:15 AM
  • First of all, this is a question not discussion. You can change the thread type to question by click on change type.

    For your question, create array list of the pictureboxes that you generate dynamically so that you will be able o delete/remove it.

    Example:

    Dim DyPic as new ArrayList   or DimDyPic as New List(of PictureBox)

    So when you add new picturebox to form also add it to arraylist/List

    kaymaf

    If that what you want, take it. If not, ignored it and no complain

    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/ .

    http://www.developerfusion.com/tools/convert/csharp-to-vb/ .

    • Marked as answer by Jeff Shan Friday, March 05, 2010 2:07 AM
    Sunday, February 28, 2010 4:24 AM
  • You can make your own context menu with features as new picture and clear pictures.

    Depending from that context menu you take actions.

    http://msdn.microsoft.com/en-us/library/aa984319(VS.71).aspx


    Success
    Cor
    • Proposed as answer by _asgar Sunday, February 28, 2010 8:39 AM
    • Marked as answer by Jeff Shan Friday, March 05, 2010 2:07 AM
    Sunday, February 28, 2010 7:42 AM