[SOLVED] [2005] CustomButtonControl - Defaults declared in New overriding values
I have a CustomButton control where I set up some Property defaults in the New of the control. Problem is that they totally override what the user has entered in the Property for the control. In fact it changes them to the values that are in the New routine when the project is run. I've done this same thing before many times without any problems. Any suggestions?
Here's the New code:
Code:
<ToolboxBitmap(GetType(BubbleButton), "BubbleButton.bmp")> _
Public Class BubbleButton : Inherits Control
Private components As System.ComponentModel.IContainer
Private ttBubbleButton As System.Windows.Forms.ToolTip = New ToolTip
Private m_Blur As Boolean = False
Private m_ButtonImage As Bitmap
Private m_ButtonImage60 As Bitmap
Private m_ButtonImage120 As Bitmap
Private m_ButtonImage180 As Bitmap
Private m_InitialSize As Size
Private m_DialogResult As Windows.Forms.DialogResult
Dim iFlag As Integer
Dim bEnter As Boolean = False
Dim dCurrentWidth, dCurrentHeight As Double
Dim dAddX, dAddY As Double
Dim bBlur As Boolean = True
Dim g1, g2 As Graphics
Dim bmpDoubleBuffer As Bitmap
Friend WithEvents tmrBubbleButton As System.Windows.Forms.Timer
Sub New()
components = New System.ComponentModel.Container
tmrBubbleButton = New System.Windows.Forms.Timer(components)
tmrBubbleButton.Interval = 10
' ---------------------------------------------------------------------
' New Button
' ---------------------------------------------------------------------
'
'
' Setup defaults
Size = New Size(48, 48)
InitialSize = New Size(Size.Width / 2, Size.Height / 2)
Blur = True
m_ButtonImage = New Bitmap(Width, Height)
m_ButtonImage60 = New Bitmap(Width, Height)
m_ButtonImage120 = New Bitmap(Width, Height)
m_ButtonImage180 = New Bitmap(Width, Height)
bmpDoubleBuffer = New Bitmap(Width, Height)
g1 = Me.CreateGraphics
End Sub
Here's the code for the Property in question:
Code:
<Category("Appearance"), _
Description("Expand to specifiy the Initial Size of the Icon when not in focus."), DefaultValueAttribute(32), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property InitialSize() As Size
Get
InitialSize = m_InitialSize
End Get
Set(ByVal Value As Size)
If Value.Width > Width Then
Value.Width = Width
End If
If Value.Height > Height Then
Value.Height = Height
End If
m_InitialSize = Value
Calc()
End Set
End Property
Resolved: [2005] CustomButtonControl - Defaults declared in New overriding values
A user in another forum found the answer. No explanantion as to why it has to be done but basically the value for 'DesignerSerializationVisibility' needs to be set to 'Visible' and not 'Content'
Code:
<Category("Appearance"), _
Description("Expand to specifiy the Initial Size of the Icon when not in focus."), DefaultValueAttribute(32), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property InitialSize() As Size
Get
InitialSize = m_InitialSize
End Get
Set(ByVal Value As Size)
If Value.Width > Width Then
Value.Width = Width
End If
If Value.Height > Height Then
Value.Height = Height
End If
m_InitialSize = Value
Calc()
End Set
End Property