PC Review


Reply
Thread Tools Rate Thread

Default Properties for Controls

 
 
XNoDE
Guest
Posts: n/a
 
      11th Oct 2003
Hi all,

VS.Net 2002.

Is there a way to set default properties for controls in the Toolbox?

There a some properties that I implement as standard in my apps and would
like to get around setting these same basic things each time a use a
control.

TIA,

XNoDE


 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      11th Oct 2003
Default values by and large are not allowed in VB.NET unless it is a
parameterized property, like with a collection:

collection.item(x) could be written as: collection(x)

In classic VB you could have default properties (such as .text with a
textbox) because of the difference between objects and data types

x = txtUser was clearly accessing the default .text property of the textbox
and

Set x = txtUser was clearly making x an object reference to the textbox
itself

In .NET, since everything is an object, the Set statement is irrelevant and
no longer supported. However, this created a problem:

Does x = txtUser mean that you want x to take on the .text property value
of the txtUser textbox or does it mean that you want x to become an object
reference to the textbox itself?

To clear up this ambiguity, MS did away with all default properties unless
that are properties that take parameters.

x = collection(x) clearly implies that you are talking about the .item
property of collection because there is a parameter present (x).

x = collection clearly implies that you want x to be an object reference to
the collection object.

Hope this helps.

Scott

"XNoDE" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
> VS.Net 2002.
>
> Is there a way to set default properties for controls in the Toolbox?
>
> There a some properties that I implement as standard in my apps and would
> like to get around setting these same basic things each time a use a
> control.
>
> TIA,
>
> XNoDE
>
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      11th Oct 2003
So, I'm reading your post again and realizing that, you don't want to set
default PROPERTIES on the toolbox controls (as you've written), you perhaps
want to set a default VALUE for some various properties of the toolbox
controls. (Sorry for the mis-read)

The controls on the toolbox represent base classes in the .NET Framework
class libraries, so the short answer is no. However, you could make a new
control that inherits from the standard one, set whatever property values
you want and use that control instead.

Public Class MyTextBox
Inherits System.Windows.Forms.Textbox

Public Sub New()
me.Text = "Some default value."
End Sub
End Class

HTH!

Scott

"XNoDE" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
> VS.Net 2002.
>
> Is there a way to set default properties for controls in the Toolbox?
>
> There a some properties that I implement as standard in my apps and would
> like to get around setting these same basic things each time a use a
> control.
>
> TIA,
>
> XNoDE
>
>



 
Reply With Quote
 
XNoDE
Guest
Posts: n/a
 
      12th Oct 2003
Thanks Scott,

Sorry for the mistype, I guess I wasn't really sure how to ask for what I
wanted. Your second post is correct. If for example I would like all of my
buttons to have the default values as:

FlatStyle = Flat
Size = 96,20

etc..

Is there a way I can have these values preset to my liking so that I only
have to build the form and code? I know it seems a trivial thing, but it's
a preference of mine.

If so, how. If I create the new class that you mention, how do I save it as
a control so that I can add it to my forms at leisure? I am familiar with
creating the class files but I've never coded extensions to a control.

Thanks again,

Xnode
"Scott M." <s-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> So, I'm reading your post again and realizing that, you don't want to set
> default PROPERTIES on the toolbox controls (as you've written), you

perhaps
> want to set a default VALUE for some various properties of the toolbox
> controls. (Sorry for the mis-read)
>
> The controls on the toolbox represent base classes in the .NET Framework
> class libraries, so the short answer is no. However, you could make a new
> control that inherits from the standard one, set whatever property values
> you want and use that control instead.
>
> Public Class MyTextBox
> Inherits System.Windows.Forms.Textbox
>
> Public Sub New()
> me.Text = "Some default value."
> End Sub
> End Class
>
> HTH!
>
> Scott
>
> "XNoDE" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi all,
> >
> > VS.Net 2002.
> >
> > Is there a way to set default properties for controls in the Toolbox?
> >
> > There a some properties that I implement as standard in my apps and

would
> > like to get around setting these same basic things each time a use a
> > control.
> >
> > TIA,
> >
> > XNoDE
> >
> >

>
>



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      12th Oct 2003
I haven't done this myself, but look into building a custom server control.
These can be added to your toolbox so that you can place them on forms just
like any other control.


"XNoDE" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks Scott,
>
> Sorry for the mistype, I guess I wasn't really sure how to ask for what I
> wanted. Your second post is correct. If for example I would like all of

my
> buttons to have the default values as:
>
> FlatStyle = Flat
> Size = 96,20
>
> etc..
>
> Is there a way I can have these values preset to my liking so that I only
> have to build the form and code? I know it seems a trivial thing, but

it's
> a preference of mine.
>
> If so, how. If I create the new class that you mention, how do I save it

as
> a control so that I can add it to my forms at leisure? I am familiar with
> creating the class files but I've never coded extensions to a control.
>
> Thanks again,
>
> Xnode
> "Scott M." <s-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > So, I'm reading your post again and realizing that, you don't want to

set
> > default PROPERTIES on the toolbox controls (as you've written), you

> perhaps
> > want to set a default VALUE for some various properties of the toolbox
> > controls. (Sorry for the mis-read)
> >
> > The controls on the toolbox represent base classes in the .NET Framework
> > class libraries, so the short answer is no. However, you could make a

new
> > control that inherits from the standard one, set whatever property

values
> > you want and use that control instead.
> >
> > Public Class MyTextBox
> > Inherits System.Windows.Forms.Textbox
> >
> > Public Sub New()
> > me.Text = "Some default value."
> > End Sub
> > End Class
> >
> > HTH!
> >
> > Scott
> >
> > "XNoDE" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi all,
> > >
> > > VS.Net 2002.
> > >
> > > Is there a way to set default properties for controls in the Toolbox?
> > >
> > > There a some properties that I implement as standard in my apps and

> would
> > > like to get around setting these same basic things each time a use a
> > > control.
> > >
> > > TIA,
> > >
> > > XNoDE
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: WebUser Controls and Public Properties - Default Value bruce barker Microsoft ASP .NET 0 30th Dec 2008 04:20 PM
Why the properties of web user controls which inherted from my custom base UI controls MISSED? ABC Microsoft C# .NET 0 21st Nov 2005 04:08 AM
Why the properties of web user controls which inherted from my custom base UI controls missed? ABC Microsoft ASP .NET 0 21st Nov 2005 04:08 AM
How to set default properties for subclassed controls Michael Rodriguez Microsoft C# .NET 2 24th Mar 2005 04:08 PM
C# User Controls - setting default properties =?Utf-8?B?Y291bnRkNA==?= Microsoft C# .NET 3 25th Feb 2005 08:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:50 PM.