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

Setting default property value for user control

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
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
Nov 21 '05 #2

P: n/a
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/de...us/cpref/html/
frlrfsystemwindowsformsdesigncontroldesignerclasst opic.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.

Nov 21 '05 #3

P: n/a
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

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:Kg**************@cpmsftngxa06.phx.gbl...
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/de...us/cpref/html/
frlrfsystemwindowsformsdesigncontroldesignerclasst opic.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.

Nov 21 '05 #4

P: n/a
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:uf**************@TK2MSFTNGP09.phx.gbl...
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
Nov 21 '05 #5

P: n/a
thanks that works now!
Nov 21 '05 #6

P: n/a
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?
"Andy Becker" wrote:
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:uf**************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.