Setting default property value for user control

B

Brian Henry

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
 
A

Andy Becker

Brian Henry said:
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

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
 
P

Peter Huang

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

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

Brian Henry

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
 
A

Andy Becker

Brian Henry said:
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
 
G

Guest

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top