Setting autosize to false

M

matthewtech

In Visual Studio 2005, using Visual Basic, Is there a way to set the
autosize property [such as in a label control] to false as a standard, and
change it to true as needed?

Or does it always start out as true when a label [or other such control] is
brought in to a form?


This is probably a very basic question, but I appreciate any help anyone can
offer.

Thanks
Matt
 
J

Jay B. Harlow [MVP - Outlook]

Matt,
The control itself (the label in this case) controls what the value defaults
to.

The only way I know of to change the default would be to inherit from Label,
creating a derived label that has the new default. Then using the derived
Label instead.

Something like:

Public Class Label
Inherits System.Windows.Forms.Label

Public Sub New()
AutoSize = False
End Sub

<System.ComponentModel.DefaultValue(False)> _
Public Overrides Property AutoSize() As Boolean
Get
Return MyBase.AutoSize
End Get
Set(ByVal value As Boolean)
MyBase.AutoSize = value
End Set
End Property

End Class

The System.ComponentModel.DefaultValueAttribute above, is suppose to tell
the forms designer that the property defaults to False and not True, so the
generated code doesn't include the value...

Unfortunately it appears that the above doesn't want to work in VS 2005
(.NET 2.0), I'll need to try it in VS 2003 this evening, as I'm sure I used
the above in VS 2002 & VS 2003 (.NET 1.x)

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| In Visual Studio 2005, using Visual Basic, Is there a way to set the
| autosize property [such as in a label control] to false as a standard, and
| change it to true as needed?
|
| Or does it always start out as true when a label [or other such control]
is
| brought in to a form?
|
|
| This is probably a very basic question, but I appreciate any help anyone
can
| offer.
|
| Thanks
| Matt
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top