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.

Derived Control Default Design Properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dennis - 31 Oct 2004 00:14 GMT
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.
Signature

Dennis in Houston

Charlie - 31 Oct 2004 02:49 GMT
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

> 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
[quoted text clipped - 6 lines]
>
> Would appreciate any help.
Dennis - 31 Oct 2004 14:19 GMT
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.

> 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
[quoted text clipped - 41 lines]
> >
> > Would appreciate any help.
Charlie - 31 Oct 2004 19:26 GMT
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.  

> 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
[quoted text clipped - 49 lines]
> > >
> > > Would appreciate any help.
Dennis - 31 Oct 2004 19:44 GMT
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.

> Try this in your derived Panel code:
>
[quoted text clipped - 71 lines]
> > > >
> > > > Would appreciate any help.

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.