473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Derived Control Default Design Properties

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
4 2412
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bruce Rusk | last post by:
I'm using Stephen Lebans' RTF2 control in a report, and have discovered what may be a slight bug in it. I have a lot of non-Western language (Chinese) text in my RTF field, and such records get...
2
by: CroDude | last post by:
Hi all! I've made a custom group-box control derived from a GroupBox. Additionally I've made a ControlDesigner derived class associated with my group box to remove some unneeded properties. But...
7
by: Jacky Luk | last post by:
Does anyone know of a downloadable Line ActiveX control which allows me to plot straight lines on a VC++.NET form? Thanks Jack
4
by: jim | last post by:
I am trying to debug a user written web control and web control designer. I found an article “Building Windows Forms Controls and Component with Rich Design-Time Features” that describes how...
2
by: Dennis | last post by:
I have a control which I wrote that has, of course, numerous properties. These properties nicely show up at design time in the property window for the user to set their value at design time. ...
11
by: Rimpinths | last post by:
I'm new at developing user controls in C#, and one thing I've noticed right off the bat is that the constructor gets called twice -- once at design time, once at run time. In short, I'm trying...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
2
by: PGP | last post by:
I recently derived from a ComboBox to make a countries combo and included it in couple of forms. The derived combo box loads an xml list of countries and uses the DataSource and DisplayMember...
1
by: =?Utf-8?B?Q2hyaXN0aWFuIFdlaW5lcnQ=?= | last post by:
Hello, I currently fight with a problem during the derivative of WinForm controls. In Visual Studio I created a new User Control. This control is derived from the DataGridView of the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.