Home All Groups Group Topic Archive Search About

Setting autosize to false

Author
3 Jun 2006 3:36 PM
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

Author
9 Jun 2006 12:34 PM
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


Show quoteHide quote
"matthewtech" <nixspam_matt_tap@yahoo.com> wrote in message
news:%2367w4NyhGHA.1260@TK2MSFTNGP05.phx.gbl...
| 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
|
|