|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis article provides a base class that helps developers build customized design-time extensions for components and controls through Smart Tag designer panels. How to Use this Helper (Base) ClassYou can easily define your custom Smart Tag panels containing your action list items (Properties, Methods (Verbs), and Texts). Here is a sample control which derives from the Here are the required steps to create your custom control designer:
Public Class mySmartTagActionList1
Inherits SmartTagActionListBase
'this variable is used to cache a reference
'to the associated control in this class
Private m_Control As XTextBox
Sub New(ByVal component As IComponent)
MyBase.New(component)
'Me.AutoShow = True
'AutoExpand this designer whenever user drag it to the Form
m_Control = CType(component, XTextBox)
'cache the control assciated to this designer
End Sub
End Class
where You may also use BackColor, ForeColor, and IsMultiline, in the below sample). Some properties are already defined in the base class (SmartTagActionListBase) such as: Name, Text, Font, RightToLeft.AddActionItems() method to add your Smart Tag panel items (ActionList items). You may use the AddActionProperty, AddActionMethod, AddActionHeader, and AddActionText methods to do this easily (see the sample code).Designer attribute to your control class like this:<Designer(GetType(SmartTagControlDesigner(Of mySmartTagActionList)))>
where the Note: if you want to define a designer for a component (not a control), just use <Designer(GetType(SmartTagComponentDesigner(Of mySmartTagActionList)))<
The Sample CodeHere is a sample control which uses a custom SmartTagPanel Designer: Imports System.ComponentModel
<Designer(GetType(SmartTagControlDesigner(Of mySmartTagActionList)))> _
Public Class XTextBox
Inherits TextBox
'... customizations
End Class
Public Class mySmartTagActionList
Inherits SmartTagActionListBase
Private m_Control As XTextBox
Sub New(ByVal component As IComponent)
MyBase.New(component)
m_Control = CType(component, XTextBox)
End Sub
Public Property BackColor() As Color
Get
Return m_Control.BackColor
End Get
Set(ByVal value As Color)
Me.SetPropertyByName(m_Control, "BackColor", value)
End Set
End Property
Public Property ForeColor() As Color
Get
Return m_Control.ForeColor
End Get
Set(ByVal value As Color)
Me.SetPropertyByName(m_Control, "ForeColor", value)
End Set
End Property
Public Property IsMultiline() As Boolean
Get
Return m_Control.Multiline
End Get
Set(ByVal value As Boolean)
Me.SetPropertyByName(m_Control, "Multiline", value)
End Set
End Property
Public Sub SwapColors()
Dim c As Color = Me.ForeColor
Me.ForeColor = Me.BackColor
Me.BackColor = c
RefreshDesigner()
End Sub
Public Overrides Sub AddActionItems()
'These properties are already defined
'in base (SmartTagActionListBase) class:
' => Name, Text, Font, RightToLeft
'Other properties/Methods should be defined in current class
AddActionHeader("Main")
AddActionProperty("Name", "Name:", "Main", "")
AddActionProperty("Text", "Text:", "Main", "")
AddActionProperty("Font", "Font:", "Main", "")
AddActionProperty("IsMultiline", "Multiline:", "", "")
AddActionHeader("Colors")
AddActionProperty("ForeColor", "ForeColor:", _
"Colors", "Sets the ForeColor")
AddActionProperty("BackColor", "BackColor:", _
"Colors", "Sets the BackColor")
AddActionText("This is my info...", "Colors")
AddActionMethod("SwapColors", "Swap Colors", _
"Colors", "Swap ForeColor/BackColor", True)
End Sub
End Class
NotesYou may see this article: Creating Property Editors in Design Time for VS.NET Easily (UITypeEditor Helper), to create UITypeEditor's easily. An 'Editor' is related to a property, but a 'Designer' is related to a control or component (a class)! By means of UITypeEditors, you can provide a custom editor window (e.g., a dropdown window) to edit each property of a control. You may mix both of the 'Designer' and 'Editor' attributes to achieve better design-time extensions for components and controls.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||