How to change properties from custom controls that inherit from System.Windows.Forms.Control at design time?
Problem: You can change the properties BackColor and Text only at runtime and not at designtime.
Question: What do I need to change or add to be be able to change properties at design time?
(if possible without having to change the base class properties of the inherited controls)
Many thanks!
Problem: You can change the properties BackColor and Text only at runtime and not at designtime.
Question: What do I need to change or add to be be able to change properties at design time?
(if possible without having to change the base class properties of the inherited controls)
Many thanks!
VB.NET:
Public MustInherit Class MyControlBase
Inherits System.Windows.Forms.Control
Protected MustOverride ReadOnly Property Control() As System.Windows.Forms.Control
Public Shadows Property BackColor() As System.Drawing.Color
Get
Return Control.BackColor
End Get
Set(ByVal value As System.Drawing.Color)
Control.BackColor = value
End Set
End Property
Public Shadows Property Text() As String
Get
Return Control.Text
End Get
Set(ByVal value As String)
Control.Text = value
End Set
End Property
'Public shadows property ...
'...
Protected Overridable Sub MyControlBase_Resize(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Me.Resize
Me.Control.Size = Me.Size
Me.Size = Me.Control.Size
End Sub
Public Sub New()
InitControl()
InitClass()
End Sub
Protected MustOverride Sub InitControl()
Protected Sub InitClass()
Me.Control.Enabled = True
Me.Control.Visible = True
Me.Control.Parent = Me
MyBase.Controls.Add(Me.Control)
End Sub
Public MustOverride Overloads Function [GetType]() As Type
End Class
Public MustInherit Class MyButtonBase
Inherits MyControlBase
Private m_btnMain As System.Windows.Forms.Button
Protected NotOverridable Overrides ReadOnly Property Control() As System.Windows.Forms.Control
Get
Return m_btnMain
End Get
End Property
'Public property ...
'...
Protected NotOverridable Overrides Sub InitControl()
m_btnMain = New System.Windows.Forms.Button
End Sub
End Class
Public MustInherit Class MyTextboxBase
Inherits MyControlBase
Private m_txtMain As System.Windows.Forms.TextBox
Protected NotOverridable Overrides ReadOnly Property Control() As System.Windows.Forms.Control
Get
Return m_txtMain
End Get
End Property
'Public property ...
'...
Protected NotOverridable Overrides Sub InitControl()
m_txtMain = New System.Windows.Forms.TextBox
End Sub
End Class
'Public MustInherit Class My...
'...
Public Class MyButton
Inherits MyButtonBase
Public Overloads Overrides Function [GetType]() As Type
Return GetType(MyButton)
End Function
End Class
Public Class MyTextbox
Inherits MyTextboxBase
Public Overloads Overrides Function [GetType]() As Type
Return GetType(MyTextbox)
End Function
End Class
'Public Class My...
'...
Last edited: