|
-
Apr 9th, 2012, 04:05 PM
#1
Thread Starter
Hyperactive Member
Custom Panel Not Acting as Parent to Contained Controls
I created a simple custom controlled Panel for double buffering. When I use the control in my toolbox it works just fine, but when I attempt to add controls inside the panel those controls aren't staying when I move the panel around. My custom panel isn't acting as the controls' parent. I verified this by looking in the designer code.
I tested a standard panel on the same form and it works perfectly normal - as I drag the parent Panel the interior controls move along with it. It is only my custom Panel which doesn't seem to detect when another control is placed within it.
Here is my constructor code:
Code:
Public Class DBPanel
Inherits System.Windows.Forms.PictureBox
Public Sub New()
MyBase.New()
SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.ResizeRedraw, True)
Me.UpdateStyles()
End Sub
End Class
What am I missing to get this control to behave like a regular panel?
Thanks!
Intermediate Level Programmer Extraordinaire 
-
Apr 9th, 2012, 04:10 PM
#2
Re: Custom Panel Not Acting as Parent to Contained Controls
PictureBoxes aren't intended to be parent (container) controls.
could you use a panel + change controlstyles in that?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2012, 04:17 PM
#3
Re: Custom Panel Not Acting as Parent to Contained Controls
something like this:
vb Code:
Public Class DBPanel
Inherits Panel
Public Sub New()
MyBase.New()
SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.ResizeRedraw, True)
Me.UpdateStyles()
End Sub
Private _image As Image
Public Property Image() As Image
Get
Return _image
End Get
Set(ByVal value As Image)
_image = value
Me.Invalidate()
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
If Me.Image IsNot Nothing Then
e.Graphics.DrawImage(Me.Image, Me.Bounds) 'stretch image
End If
MyBase.OnPaint(e)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2012, 04:33 PM
#4
Thread Starter
Hyperactive Member
Re: Custom Panel Not Acting as Parent to Contained Controls
I cut an pasted the wrong custom control code - this is from my custom picturebox (which works fine). If you just replace "Inherits System.Windows.Forms.PictureBox" with "Inherits System.Windows.Forms.Panel" that would make my code accurate.
I truly apologize for the error!
Intermediate Level Programmer Extraordinaire 
-
Apr 9th, 2012, 05:09 PM
#5
Re: Custom Panel Not Acting as Parent to Contained Controls
ok. i tried it. it worked ok for me.
is there any other code involved?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2012, 05:19 PM
#6
Thread Starter
Hyperactive Member
Re: Custom Panel Not Acting as Parent to Contained Controls
Thanks for your efforts. The only relevant code I can think of is in the designer. What is see is this:
Code:
Me.Controls.Add(Me.DbPanel7)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
DbPanel is the custom panel and the labels are supposed to be inside the panel. It should look like this:
Code:
Me.Controls.Add(Me.DbPanel7)
Me.DbPanel7.Controls.Add(Me.Label3)
Me.DbPanel7.Controls.Add(Me.Label2)
Me.DbPanel7.Controls.Add(Me.Label1)
No matter where I place these labels the designer falls to have them contained in my panel. I have learned the hard way never to mess with designer code, so I haven't attempted to change anything.
Very frustrating...
Intermediate Level Programmer Extraordinaire 
-
Apr 9th, 2012, 05:57 PM
#7
Re: Custom Panel Not Acting as Parent to Contained Controls
did you add them to the form + drag them onto the panel?
all i can suggest is that you make sure the panel is focused when adding controls.
your 2nd snippet is how the designer should be + it should be ok to go ahead + change it.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2012, 07:09 PM
#8
Thread Starter
Hyperactive Member
Re: Custom Panel Not Acting as Parent to Contained Controls
When I switched the code in the designer it switched it right back! It's almost funny how badly this code does not want to work. 
One other interesting bit of information I just noticed - my custom panels do not have 4-way arrow icons in the upper left corner that regular panels possess. Whereas in a regular panel you have to drag and drop using this icon my panels can be dragged and dropped from anywhere inside the panel. Does this provide a hint?
Intermediate Level Programmer Extraordinaire 
-
Apr 9th, 2012, 07:12 PM
#9
Re: Custom Panel Not Acting as Parent to Contained Controls
it adds to the evidence that there's something wrong, but it doesn't lead to an easy solution.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|