Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / September 2005

Tip: Looking for answers? Try searching our database.

Panel Inside Custom control set to design

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RoadRunner News - 16 Sep 2005 22:03 GMT
"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."
Mick Doherty - 17 Sep 2005 11:12 GMT
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
///

Signature

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

> "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."

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.