.Net Inherited Control Property Default

Posted by Yisman on Stack Overflow See other posts from Stack Overflow or by Yisman
Published on 2010-03-16T16:59:28Z Indexed on 2010/03/16 17:01 UTC
Read the original article Hit count: 223

Filed under:
|
|
|

Hello fellows Im trying to make a simple "ButtonPlus" control. the main idea is to inherit from the button control and add some default property values (such as font,color,padding...)

No matter how i try, the WinForm always generates (or "serializes") the property value in the client forms

the whole point is to have minimal and clean code, not that every instance of the buttonPlus should have 5 lines of init code.

I want that the form designer should not generate any code for theses properties and be able to control them from the ButtonPlus code. In other words, if I change the ForeColor from red to blue only 1 single bingle line of code in the app should change.

heres my code so far. as you can see, ive tried using defaultvalue, reset , shouldserialize.... anything i was able to find on the web!

Public Class ButtonPlus Inherits Button Sub New() 'AutoSize = True AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink Font = New System.Drawing.Font("Arial", 11.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(177, Byte)) Padding = New System.Windows.Forms.Padding(3) Anchor = AnchorStyles.Left + AnchorStyles.Right + AnchorStyles.Top ForeColor = Color.Aqua End Sub ' _ 'Public Overrides Property AutoSize() As Boolean ' Get ' Return MyBase.AutoSize ' End Get ' Set(ByVal value As Boolean) ' MyBase.AutoSize = value ' End Set 'End Property

Public Function ShouldSerializeAutoSize() As Boolean
    Return False ' Not AutoSize = True
End Function

Public Function ShouldSerializeForeColor() As Boolean
    Return False 'Not ForeColor = Color.Aqua
End Function

Public Overrides Sub ResetForeColor()
    ForeColor = Color.Aqua
End Sub

End Class

Thank you very much for taking the time to look this over and answer all the best

© Stack Overflow or respective owner

Related posts about .NET

Related posts about inheritance