|
The Control Designer:
adxSuperPanel
has a control designer inheriting from the
ParentControlDesigner
class. One needs to distinguish between the
control Setstyle(ControlStyles.ContainerControl,
True) statement in the constructor
and the ParentControlDesigner
base class of the control designer. The style will
enable you to create a control that includes other controls,
yet only the specific designer will generate the underlying
code that makes the panel a parent of any sited child
controls:
Me.AdxSuperPanel1.Controls.Add(Me.Button1)
I've used the designer for several other design time functions.
(Control designers have absolutely no life during run
time!) . You may use any of the
Verbs in the the context menu or the
property grid to access often used properties without
going directly to the property line on the grid. When
you change properties using verbs, .NET will update the
Property Grid but you need the
RaisedComponentChanged method of the
ParentControlDesigner
to serialize the change:
-
Private
Sub WorkNewValues(ByVal
MainDesc As Object,
ByVal prop
As
PropertyDescriptor, ByVal
oldValue As Object,
ByVal NewValue
As Object)
-
prop.SetValue(MainDesc, NewValue)
Me.RaiseComponentChanged(prop,
oldValue, NewValue) End
Sub

ControlBorderColor You may
select the color of the dashed border at design time
a design time property.
Transparent BackColor adxSuperPanel uses
the Transparent backcolor. The statement
Setstyle(ControlStyles.SupportsTransparentBackColor, True)
enables the control to use the Transparent color.
ControlBorderColor
Property This is a
design time only property. It will let you change the
color of the dashed border to suit your needs.
You override the
OnPaintAdornments
protected method.
Protected
Overrides
Sub OnPaintAdornments(ByVal
pe As
PaintEventArgs) MyBase.OnPaintAdornments(pe)
_ borderPen.Color =
_parent.ControlBorderColor
pe.Graphics.DrawRectangle(_borderPen, 0, 0,
_parent.Width - 1, _parent.Height - 1)
End Sub
How To Minimize Winform Designer
Generated Code:
Many .NET
forums are loaded with questions about the correct
manner to use the DefaultValue.
adxSuperPanel has a
very small foot print once you drop it on the form. The
designer generates just five lines. The secret?
Correct usage of Defaultvalue in front of
each property. Also, in many cases you are
better off not having the
SerializableAttribute() in base classes that
have Color properties. Here's a typical designer
generated code:
'AdxSuperPanel3
' Me.AdxSuperPanel3.Location = New
System.Drawing.Point(400, 48) Me.AdxSuperPanel3.Name
= "AdxSuperPanel3" Me.AdxSuperPanel3.Size = New
System.Drawing.Size(64, 120)
Me.AdxSuperPanel3.TabIndex = 2 Me.AdxSuperPanel3.Text
= "AdxSuperPanel3" '
Classes need
special handling as suggested by Microsoft, I've used
the following approach whenever I needed to
serialize a whole class. Throughout my code I've used
this approach to serialize fonts. In the
PropProvider class I've used this
approach to serialize the
Gradient property
Private _font as Font =
Nothing
Private _topcontrol
as adxSuperPanel
Public
Function
ShouldSerializeFont() As Boolean
Return Not (_font Is Nothing) End Function
Public
Sub ResetFont()
_font = Nothing End Sub
Public
Property Font() As
Font
Get
If Not (_font Is
Nothing)
Then
Return
Me._font
End If
Return _topcontrol.Font
End Get
Set(ByVal
Value As
Font)
If Not Value
Is Me._font
Then
Me.font = Value
Invalidate()
End If
End Set End Property
Color:
DefaultValue(GetType(Color),
"Black")
Integer:
DefaultValue(GetType(Integer),
"25") 'or any numeric
Enum:
DefaultValue(GetType(ContentAlignment),
"TopLeft")
Boolean:
DefaultValue(GetType(Boolean),
"False")
Image:
DefaultValue(GetType(Image),
Nothing)
String:
DefaultValue(GetType(String),
"")
Round Corners: All .NET
controls are rectangular. So what about round corners? We
can create odd shapes because the control's BackColor
is transparent. The round effect is GDI+ graphical
path, rendered to order.
adxSuperPanel renders a four round corners
rectangle into a graphical path. Corners are arcs measured
90 degrees.
Friend
Shared
Function
RoundRectangleAllSides(ByVal
gp As GraphicsPath, ByVal x As Short, ByVal y As Short,
ByVal width As Short, ByVal height As Short, ByVal
radius As Short) As GraphicsPath
'No need for the connecting lines
- closefigure will do...
Dim coter
As Short = radius * 2
gp.AddArc(x, y, coter,
coter, 180, 90) gp.AddArc(x
+ width - coter, y, coter, coter, 270, 90)
gp.AddArc(x + width -
coter, y + height - coter, coter, coter, 0, 90)
gp.AddArc(x, y + height -
coter, coter, coter, 90, 90) gp.CloseFigure()
Return gp
End Function
|