Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project i have moving picturebox array & if they intersect treeview will disable.& when i rightclick on the picturebox it will delete.After deleting picturebox its effects still there.When other picturebox moving on that deleted area
still treeview is disabled.i used this code.

VB
Me.Controls.Remove(a)

where a= new picturebox
Posted
Comments
Sergey Alexandrovich Kryukov 26-Jun-12 14:42pm    
Perhaps more information could help. What is "its effects"? Any code sample?
--SA

1 solution

Hi!

My guess is that you are using a single variable to generate an array of picture boxes. So i would suggest this to work around the issue:

STEP 1. When creating picture box assigned a unique name to it. like : pic1, pic2, pic3 .... etc

e.g.,


VB
a = New PictureBox()
counter += 1      ' a global variable initialized with zero
a.Name = "a" & counter.ToString()

Me.Controls.Add(a)

'Event Handlers
AddHandler a.MouseDown, AddressOf a_MouseDown
AddHandler a.MouseMove, AddressOf a_Mousemove
AddHandler a.MouseUp,   AddressOf a_Mouseup


STEP 2. Use Control.RemoveByKey() method to remove it:

VB
Private Sub a_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
       If e.Button = Windows.Forms.MouseButtons.Right Then
            Me.Controls.RemoveByKey(CType(sender, PictureBox).Name)'remove control
            Me.Invalidate(True)       ' redraw controls
        End If
End Sub
 
Share this answer
 
Comments
_Amy 31-Jul-12 2:22am    
My +5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900