Click here to Skip to main content
6,596,602 members and growing! (22,863 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » Samples     Intermediate License: The Code Project Open License (CPOL)

Smart-Tag Control Designer (Extending Design-Time Support)

By S.Serpooshan

Helps developers to build customized design-time extensions for components and controls through Smart Tag designer panels.
Windows, .NETVS2005, Dev
Posted:12 Jan 2007
Updated:22 Jan 2007
Views:24,810
Bookmarked:67 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
17 votes for this article.
Popularity: 5.61 Rating: 4.56 out of 5
1 vote, 5.9%
1

2

3
3 votes, 17.6%
4
13 votes, 76.5%
5

Introduction

This 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) Class

You 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 TextBox control and uses a custom designer (mySmartTagActionList). The items are added in the AddActionItems() method. Any property or method you want to add should be defined in your SmartTagActionList class which is derived from the SmartTagActionListBase class.

Here are the required steps to create your custom control designer:

  • Define your control (or component) class (e.g., XTextBox)
  • Define a DesignerActionList class which inherits from SmartTagActionListBase. This part of the code should also be inserted to its body:
  • 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 XTextBox is the type (or class name) of your control. Here, the m_Control variable is used to cache a reference to the associated control of this designer for later uses.

    You may also use Me.AutoShow = True in this constructor routine to auto-expand (auto-show) it whenever the user drags your control into the form.

  • Define the properties/methods you want (e.g., BackColor, ForeColor, and IsMultiline, in the below sample). Some properties are already defined in the base class (SmartTagActionListBase) such as: Name, Text, Font, RightToLeft.
  • Override the 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).
  • Add a Designer attribute to your control class like this:
  • <Designer(GetType(SmartTagControlDesigner(Of mySmartTagActionList)))>

    where the mySmartTagActionList is the name of your SmartTagActionList class.

    Note: if you want to define a designer for a component (not a control), just use SmartTagComponentDesigner instead of SmartTagControlDesigner:

    <Designer(GetType(SmartTagComponentDesigner(Of mySmartTagActionList)))<

The Sample Code

Here 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

Notes

You 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

S.Serpooshan


Member

Occupation: Web Developer
Location: United States United States

Other popular .NET Framework articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
GeneralSmart Tag crashes with Swap Colors PinmemberDerek Hart6:59 2 Mar '09  
GeneralWhere can I create my own error? PinmemberDerek Hart6:56 2 Mar '09  
General'SmartMoveTag' from Panel Inhereted control disapears. Pinmembermagiel_van_gaalen0:23 8 Sep '08  
AnswerRe: 'SmartMoveTag' from Panel Inhereted control disapears. PinmemberMember 204662513:57 26 Nov '08  
GeneralC# Pinmembersabrown10011:53 18 Oct '07  
QuestionCreate composite controls Pinmemberbmwgamil14:09 9 Aug '07  
QuestionHow to add smart tag to Custom Control inherited from ComboBox PinmemberKristipati Subramanyam20:04 3 Aug '07  
GeneralCustom UITypeEditor on ActionList PinmemberDevDiver6:26 22 Jan '07  
GeneralRe: Custom UITypeEditor on ActionList PinmemberS.Serpooshan7:27 22 Jan '07  
GeneralRe: Custom UITypeEditor on ActionList PinmemberDevDiver7:55 22 Jan '07  
GeneralAutoExpand PinmemberHenrique Carvalho23:36 21 Jan '07  
GeneralRe: AutoExpand [modified] PinmemberS.Serpooshan5:06 22 Jan '07  
GeneralRe: AutoExpand PinmemberHenrique Carvalho6:09 22 Jan '07  
GeneralThank you Pinmemberbabakzawari21:31 18 Jan '07  
GeneralRe: Thank you PinmemberS.Serpooshan7:00 19 Jan '07  
Generalsolved PinmemberSaadz11:56 14 Jan '07  
Generalhelps me alot, thanks Pinmemberahmed452:19 13 Jan '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Jan 2007
Editor: Smitha Vijayan
Copyright 2007 by S.Serpooshan
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project