Thank you for following up that it worked!
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
| Ok,
| it works great!
| Thank you very much!
|
| Jordi Rico ha escrito:
|
| > Thanks Jay, I'll try today and I'll tell how it works.
| >
| > Jay B. Harlow [MVP - Outlook] ha escrito:
| >
| > > Marina,
| > > He has Me.AutoSize = False in his constructor. His overridden Property
then
| > > does a MyBase.AutoSize = false. Net effect is the same thing.
| > >
| > > | I thought the DefaultValue attribute just determines whether or not
design
| > > | time code is generated when the property is the default value.
| > > Ah! There's the rub! or should I say there's the bug!
| > >
| > > The DefaultValueAttribute determines whether or not design time code
is
| > > generated. The constructor determines the runtime code.
| > >
| > >
| > > Well apparently in the case of Label, the new .NET 2.0 layout manager
| > > decides to ignore both & applies AutoSize = True to the control...
| > >
| > > A fellow MVP uses the following code as a workaround:
| > >
| > > Public Class LabelEx
| > > Inherits System.Windows.Forms.Label
| > >
| > > Private m_inited As Boolean
| > >
| > > Sub New()
| > > MyBase.New()
| > > Me.ForeColor = Color.Black
| > > Me.AutoSize = False
| > > Me.Height = 16
| > > End Sub
| > >
| > > Protected Overrides Sub InitLayout()
| > > MyBase.InitLayout()
| > > m_inited = True
| > > End Sub
| > >
| > >
| > > <System.ComponentModel.DefaultValue(False)> _
| > > Public Overrides Property AutoSize() As Boolean
| > > Get
| > > Return MyBase.AutoSize
| > > End Get
| > > Set(ByVal value As Boolean)
| > > If Me.DesignMode AndAlso Not m_inited Then Return
| > > MyBase.AutoSize = value
| > > End Set
| > > End Property
| > >
| > > End Class
| > >
| > >
| > >
| > > --
| > > Hope this helps
| > > Jay B. Harlow [MVP - Outlook]
| > > .NET Application Architect, Enthusiast, & Evangelist
| > > T.S. Bradley -
http://www.tsbradley.net
| > >
| > >
| > > | > > | Wouldn't you have to in your constructor set MyBase.AutoSize =
False?
| > > |
| > > | I thought the DefaultValue attribute just determines whether or not
design
| > > | time code is generated when the property is the default value. When
the
| > > | property is already the default value, it doesn't bother generating
the
| > > line
| > > | of code, and the property value is not bold in the properties
window. When
| > > | it's anything other then the default, only then does it bother
generating
| > > a
| > > | line for it, and then it looks bold in the properties window so it's
| > > easier
| > > | to tell you've modified it.
| > > |
| > > | | > > | > Hi, I've made the next inherited class in Visual Studio 2005:
| > > | >
| > > | > Public Class LabelEx
| > > | > Inherits System.Windows.Forms.Label
| > > | >
| > > | > Sub New()
| > > | > MyBase.New()
| > > | > Me.ForeColor = Color.Black
| > > | > Me.AutoSize = False
| > > | > Me.Height = 16
| > > | > 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 problem is that Autosize Property remains always as true when
I go
| > > | > to design mode and put my LabelEx from the ToolBox to the form.
Looking
| > > | > at the designer file, I can see as every property I have set to
all my
| > > | > other extended controls is correct, except from autosize for
labels...
| > > | > Any idea??? I've been unable to find this anywhere, and it looks
like a
| > > | > bug, doesn't it? By the way, this code works properly in VS 2003,
and
| > > | > although the default in 2003 is Autosize=false, if I put it to
true, it
| > > | > works with no problem, the designer sets the value I've said...
| > > | >
| > > |
| > > |
|