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

Derived Control Default Design Properties

P: n/a
I am trying to set the default design proerties in a control I have derived
from the Panel Class. I thought I'd found how to do it from the MSDN but the
following line doesn't work:

Inherits System.Windows.Forms.Design.ControlDesigner

I get an error saying that the Type is not defined. I cut and pasted all
the imports and line from the MSDN.

Would appreciate any help.
--
Dennis in Houston
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In a User Control Library, you can create a new UserControl class. This is
the class you would use for controls that are made of several constituent
controls. If you want to just inherit from Panel, change the last item in
the inherits statement from UserControl to Panel. In the InitializeComponent
routine, remove me.size = LxW.

Instead of Load, the inherited control uses:

Protected Overrides Sub OnCreateControl()
MyBase.BackColor = Color.Yellow
MyBase.BorderStyle = BorderStyle.Fixed3D
MyBase.OnCreateControl()
End Sub

Be sure that last line gets in there. The lines above that would be one way
to set defaults for existing properties. If you have an added property, you
can set the default property value in the private variable that holds the
value. If you subsequently change the value in the Properties Window, that
value would be over written.

Private _Field As String = "StartField"
Public Property Field() As String
Get
Return Me._Field
End Get
Set(ByVal Value As String)
Me._Field = Value
End Set
End Property

When you customize the toolbox, browse to the .dll created for the
UserControl Library project.

www.charlesfarriersoftware.com

"Dennis" wrote:
I am trying to set the default design proerties in a control I have derived
from the Panel Class. I thought I'd found how to do it from the MSDN but the
following line doesn't work:

Inherits System.Windows.Forms.Design.ControlDesigner

I get an error saying that the Type is not defined. I cut and pasted all
the imports and line from the MSDN.

Would appreciate any help.
--
Dennis in Houston

Nov 21 '05 #2

P: n/a
Charlie, thanks for you answer and I learned some thing from it. However,
what I want to do is show defaults in the Properties Box at Design time. For
example, I have added a property to my derived class (derives from panel
class) for HorzAlignment and I want it to show the designer a default of
"Center" instead of the current "Near".

Thanks again for your answer.

"Charlie" wrote:
In a User Control Library, you can create a new UserControl class. This is
the class you would use for controls that are made of several constituent
controls. If you want to just inherit from Panel, change the last item in
the inherits statement from UserControl to Panel. In the InitializeComponent
routine, remove me.size = LxW.

Instead of Load, the inherited control uses:

Protected Overrides Sub OnCreateControl()
MyBase.BackColor = Color.Yellow
MyBase.BorderStyle = BorderStyle.Fixed3D
MyBase.OnCreateControl()
End Sub

Be sure that last line gets in there. The lines above that would be one way
to set defaults for existing properties. If you have an added property, you
can set the default property value in the private variable that holds the
value. If you subsequently change the value in the Properties Window, that
value would be over written.

Private _Field As String = "StartField"
Public Property Field() As String
Get
Return Me._Field
End Get
Set(ByVal Value As String)
Me._Field = Value
End Set
End Property

When you customize the toolbox, browse to the .dll created for the
UserControl Library project.

www.charlesfarriersoftware.com

"Dennis" wrote:
I am trying to set the default design proerties in a control I have derived
from the Panel Class. I thought I'd found how to do it from the MSDN but the
following line doesn't work:

Inherits System.Windows.Forms.Design.ControlDesigner

I get an error saying that the Type is not defined. I cut and pasted all
the imports and line from the MSDN.

Would appreciate any help.
--
Dennis in Houston

Nov 21 '05 #3

P: n/a
Try this in your derived Panel code:

Private _HorzAlignment As String = "Near"
Public Property Field() As String
Get
Return Me._HorzAlignment
End Get
Set(ByVal Value As String)
Me._HorzAlignment = Value 'Additional code to modify HorzAlignment End Set
End Property
That should work for the Property Window. That would set the initial value
to "Near".
I have found that sometimes I have the Toolbox pointing to a .dll that is
not being updated by the Re-build. You can check that by making another
temporary change to the control that you know you would be able to see.

I might also suggest that you use an Enum for your variable type for
HorzAlignment, since it is likely a limited number of possible items.
"Dennis" wrote:
Charlie, thanks for you answer and I learned some thing from it. However,
what I want to do is show defaults in the Properties Box at Design time. For
example, I have added a property to my derived class (derives from panel
class) for HorzAlignment and I want it to show the designer a default of
"Center" instead of the current "Near".

Thanks again for your answer.

"Charlie" wrote:
In a User Control Library, you can create a new UserControl class. This is
the class you would use for controls that are made of several constituent
controls. If you want to just inherit from Panel, change the last item in
the inherits statement from UserControl to Panel. In the InitializeComponent
routine, remove me.size = LxW.

Instead of Load, the inherited control uses:

Protected Overrides Sub OnCreateControl()
MyBase.BackColor = Color.Yellow
MyBase.BorderStyle = BorderStyle.Fixed3D
MyBase.OnCreateControl()
End Sub

Be sure that last line gets in there. The lines above that would be one way
to set defaults for existing properties. If you have an added property, you
can set the default property value in the private variable that holds the
value. If you subsequently change the value in the Properties Window, that
value would be over written.

Private _Field As String = "StartField"
Public Property Field() As String
Get
Return Me._Field
End Get
Set(ByVal Value As String)
Me._Field = Value
End Set
End Property

When you customize the toolbox, browse to the .dll created for the
UserControl Library project.

www.charlesfarriersoftware.com

"Dennis" wrote:
I am trying to set the default design proerties in a control I have derived
from the Panel Class. I thought I'd found how to do it from the MSDN but the
following line doesn't work:

Inherits System.Windows.Forms.Design.ControlDesigner

I get an error saying that the Type is not defined. I cut and pasted all
the imports and line from the MSDN.

Would appreciate any help.
--
Dennis in Houston

Nov 21 '05 #4

P: n/a
Charlie, you are absolutely correct. When I change the setting in my control
then rebuild it, the new values show up in the Design time Property table
exactly as I had set them to before the rebuild. Thanks a lot.

"Charlie" wrote:
Try this in your derived Panel code:

Private _HorzAlignment As String = "Near"
Public Property Field() As String
Get
Return Me._HorzAlignment
End Get
Set(ByVal Value As String)
Me._HorzAlignment = Value

'Additional code to modify HorzAlignment
End Set
End Property


That should work for the Property Window. That would set the initial value
to "Near".
I have found that sometimes I have the Toolbox pointing to a .dll that is
not being updated by the Re-build. You can check that by making another
temporary change to the control that you know you would be able to see.

I might also suggest that you use an Enum for your variable type for
HorzAlignment, since it is likely a limited number of possible items.
"Dennis" wrote:
Charlie, thanks for you answer and I learned some thing from it. However,
what I want to do is show defaults in the Properties Box at Design time. For
example, I have added a property to my derived class (derives from panel
class) for HorzAlignment and I want it to show the designer a default of
"Center" instead of the current "Near".

Thanks again for your answer.

"Charlie" wrote:
In a User Control Library, you can create a new UserControl class. This is
the class you would use for controls that are made of several constituent
controls. If you want to just inherit from Panel, change the last item in
the inherits statement from UserControl to Panel. In the InitializeComponent
routine, remove me.size = LxW.

Instead of Load, the inherited control uses:

Protected Overrides Sub OnCreateControl()
MyBase.BackColor = Color.Yellow
MyBase.BorderStyle = BorderStyle.Fixed3D
MyBase.OnCreateControl()
End Sub

Be sure that last line gets in there. The lines above that would be one way
to set defaults for existing properties. If you have an added property, you
can set the default property value in the private variable that holds the
value. If you subsequently change the value in the Properties Window, that
value would be over written.

Private _Field As String = "StartField"
Public Property Field() As String
Get
Return Me._Field
End Get
Set(ByVal Value As String)
Me._Field = Value
End Set
End Property

When you customize the toolbox, browse to the .dll created for the
UserControl Library project.

www.charlesfarriersoftware.com

"Dennis" wrote:

> I am trying to set the default design proerties in a control I have derived
> from the Panel Class. I thought I'd found how to do it from the MSDN but the
> following line doesn't work:
>
> Inherits System.Windows.Forms.Design.ControlDesigner
>
> I get an error saying that the Type is not defined. I cut and pasted all
> the imports and line from the MSDN.
>
> Would appreciate any help.
> --
> Dennis in Houston

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.