Results 1 to 3 of 3

Thread: nesting picture boxes and their parent function

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    33

    nesting picture boxes and their parent function

    I have inserted a picture box inside which there is another smaller picture box. I have made the back color of the smaller picturebox to transparent, for this to work properly i have run the following code in form1_load.
    "SmallerPictureBox.Parent = BiggerPictureBox"

    And it works fine.
    But now i need to insert a small label inside the SmallerPictureBox and make the back color of the label also transparent. to do that i used this code:
    "label.Parent = SmallerPictureBox"

    But now this is not working and the label is not being seen at all.
    And i have put these 2 lines of code in this same order also.
    Wat shud i do so that the label is seen on the SmallerPictureBox and also be transparent??
    Please Help.

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: nesting picture boxes and their parent function

    Hi Suraj,

    The Location, Left, Top etc. properties of a control are always relative to the control's Parent. So if you can't see the Label at all, you are probably not resetting the Left and Top of the label correctly.

    Here's a little sub I use for this purpose. It uses PointToScreen+PointToClient to make it completely accurate (allow for any border on the new parent control):
    Code:
    	Private Sub Reparent(child As Control, newParent As Control)
    		Dim childLocation As Point = child.Parent.PointToScreen(child.Location)
    		child.Parent = newParent
    		childLocation = newParent.PointToClient(childLocation)
    		child.Left = childLocation.X
    		child.Top = childLocation.Y
    	End Sub
    
    	'example of use:
    	Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    		Reparent(PictureBox2, PictureBox1)
    		Reparent(Label1, PictureBox2)
    	End Sub
    BB

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    33

    Re: nesting picture boxes and their parent function

    Thank You very much Boops Boops.

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