CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2000
    Location
    Austin, Texas
    Posts
    5

    Trying to remove controls at runtime

    I have created 100 picture boxes on anouther picture box. I did this using "Public WithEvents extStars As PictureBox" and adding them with this libne of code
    "Set extStars = frmGMap.Controls.Add("vb.picturebox", stStarID, Picture2)". Now I am trying to remove them so I can lay down a different set of pictures. I tried using the only example given in MSDN which was "frmGMap.Controls.Remove (stStarID)". If any one could please give me a hand I would be grateful.

    Thanks,
    Deebo


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Trying to remove controls at runtime

    If the controls are in a control array, why couldn't you just use the unload method?
    paste this code in a form and then run it, look at the text boxes, then double click the form and watch them disappear.

    'txtMain(0).text was created by hand at design time
    option Explicit

    private Sub Form_DblClick()
    Unload txtMain(2)
    Unload txtMain(1)
    End Sub

    private Sub Form_Load()
    Dim ctl as TextBox
    Load txtMain(1)
    txtMain(1).Left = 0
    txtMain(1).Top = 0
    Load txtMain(2)
    txtMain(2).Left = 200
    txtMain(2).Top = 200
    Load txtMain(3)
    txtMain(3).Left = 400
    txtMain(3).Top = 400

    for Each ctl In me.Controls
    ctl.Visible = true
    next
    End Sub




    Hope this helps,
    john


    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Feb 2000
    Location
    Austin, Texas
    Posts
    5

    Re: Trying to remove controls at runtime

    What I've done is put those controls inside a picture box that is inside anouther picture box. So usnig your method how would I specify that I want the controls to go inside of a picture box. The way I did it I specified where the control should go. It looks like your way only places the control on the form itself and not on anything else. Now I have never used your method before so I might be over looking how to do it. So any help there would be gratefully accepted.

    Thank You Again,
    Deebo


  4. #4
    Join Date
    Feb 2000
    Location
    Austin, Texas
    Posts
    5

    Re: Trying to remove controls at runtime

    I played with it some more and I have got your code to work with what I need. Thank You so much for your help.


    Deebo


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured