By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,989 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,989 IT Pros & Developers. It's quick & easy.

Custom control with panel...

P: n/a
I'm trying to build a custom control that includes a panel control on
it. However, in design-time when I drag a new control (e.g. a textbox,
etc) into the panel, it's not added in the panel--just the overall
control.

* I do not want the entire user control to be a panel/container
control. I just want the panel part of it to work as expected.

Any suggestions?

thanks,
Todd

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
<to********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I'm trying to build a custom control that includes a panel control on
it. However, in design-time when I drag a new control (e.g. a textbox,
etc) into the panel, it's not added in the panel--just the overall
control.

* I do not want the entire user control to be a panel/container
control. I just want the panel part of it to work as expected.

Any suggestions?

thanks,
Todd

Nov 21 '05 #2

P: n/a
Thank you. That does work. However, if possible i would like to the the
panel on the custom control while designing the custom control. I have
other controls on it, and i'd like to see them all together without
having to compile the project and drag the control onto a form.

thank you,
todd

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.