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 / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

Setting default property value for user control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Henry - 17 Aug 2004 14:42 GMT
Hi,

I have a user control who's class starts like this

Imports System.Drawing

Imports System.Drawing.Drawing2D

Imports System.ComponentModel

<ToolboxBitmap(GetType(Windows.Forms.Panel)), Category("test")> _

Public Class dialogTopBar

Inherits System.Windows.Forms.UserControl

what I want to do is set the dock property's default value to top so when
its added to the form it automatically docks to the top dock location, how
would I go about doing that in this declaration? thanks
Andy Becker - 17 Aug 2004 16:44 GMT
> Hi,
>
[quoted text clipped - 15 lines]
> its added to the form it automatically docks to the top dock location, how
> would I go about doing that in this declaration? thanks

You will need a custom designer, and in the OnSetComponentDefaults override,
do something like:

 MyBase.Control.Dock = ...

Let me know if you need more info on custom designers.  Meantime, a look at
DesignerAttribute should point you the right direction to get going.

Best Regards,

Andy
"Peter Huang" - 18 Aug 2004 07:04 GMT
Hi Brian,

I agree with Andy's suggestion, here goes the code.
<DesignerAttribute(GetType(TestControlDesigner))> _
Public Class UserControl1
   Inherits System.Windows.Forms.UserControl

'........ omit the generated code

End Class

Public Class TestControlDesigner
   Inherits System.Windows.Forms.Design.ControlDesigner
   Public Overrides Sub OnSetComponentDefaults()
       MyBase.Control.Dock = DockStyle.Top
   End Sub
End Class

You may also take a look at the ControlDesigner Class.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformsdesigncontroldesignerclasstopic.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Brian Henry - 18 Aug 2004 13:59 GMT
i cant get the designerattribute property to show up... even with importing
all these...

Imports System

Imports System.ComponentModel

Imports System.ComponentModel.Design

Imports System.Collections

Imports System.Drawing

Imports System.Diagnostics

Imports System.Windows.Forms

Imports System.Windows.Forms.Design

> Hi Brian,
>
[quoted text clipped - 26 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Andy Becker - 18 Aug 2004 16:39 GMT
> i cant get the designerattribute property to show up... even with importing
> all these...

Oops, that is a confusing part about attributes.  You don't acually use
include "Attribute".  Try this:

System.ComponentModel.Designer(GetType(...

Best Regards,

Andy
Brian Henry - 18 Aug 2004 18:40 GMT
thanks that works now!
Dennis - 30 Oct 2004 22:33 GMT
When I follow the example in the MDSN on DesignerAttrributes, for the statement

Inherits System.Windows.Forms.Design.ControlDesigner

I get an error saying that the type is not defined.  I copied all the
imports and other parts directly from the MSDN using cut and paste.  Any idea
what's going on?

> > i cant get the designerattribute property to show up... even with
> importing
[quoted text clipped - 8 lines]
>
> Andy

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.