all groups > dotnet windows forms designtime > september 2005 >
You're in the

dotnet windows forms designtime

group:

Panel Inside Custom control set to design


Panel Inside Custom control set to design RoadRunner News
9/16/2005 5:03:30 PM
dotnet windows forms designtime:
"I have a custom control that has a panel inside of it. I need the panel
exposed as a control in design time when I place an instance of the custom
control onto a form. In other words, I need to be able to put objects into
the panel when the custom control has been placed onto a form. By default,
the panel is not in design time, and thus I can not place objects inside of
it."

Re: Panel Inside Custom control set to design Mick Doherty
9/17/2005 11:12:48 AM
You need to implement a Designer for your usercontrol and create the panel
in it's OnSetComponentDefaults() method.

Here's a basic example in VB.

note: you need to add a reference to System.Design.dll.

\\\
Imports System.ComponentModel
Imports System.ComponentModel.Design

<Designer(GetType(MyDesigner))> _
Public Class MyUserControl
Inherits System.Windows.Forms.UserControl

'Your code here

End Class

Friend Class MyDesigner
Inherits System.Windows.Forms.Design.ControlDesigner

Public ReadOnly Property DesignerHost() As IDesignerHost
Get
Return DirectCast(GetService(GetType(IDesignerHost)), _
IDesignerHost)
End Get
End Property

Public ReadOnly Property HostControl() As Control
Get
Return Me.Control
End Get
End Property

Public Overrides Sub OnSetComponentDefaults()
Dim p As Panel = DirectCast(Me.DesignerHost.CreateComponent _
(GetType(Panel)), Panel)
p.Location = New Point(10, 40)
p.Size = New Size(HostControl.Width - 20, HostControl.Height - 50)
p.Anchor = AnchorStyles.Left Or AnchorStyles.Top Or _
AnchorStyles.Right Or AnchorStyles.Bottom
HostControl.Controls.Add(p)
End Sub

End Class
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


[quoted text, click to view]

AddThis Social Bookmark Button