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

Default Properties for Controls

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


P: n/a
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" <xn***@sbcglobal.net> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #2

P: n/a
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" <xn***@sbcglobal.net> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #3

P: n/a
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-***@badspamsnet.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
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" <xn***@sbcglobal.net> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
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


Nov 20 '05 #4

P: n/a
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" <xn***@sbcglobal.net> wrote in message
news:ev*************@TK2MSFTNGP10.phx.gbl...
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-***@badspamsnet.net> wrote in message
news:OV**************@TK2MSFTNGP11.phx.gbl...
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" <xn***@sbcglobal.net> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
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



Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.