Results 1 to 5 of 5

Thread: [RESOLVED] [2005] smart tags

  1. #1

    Thread Starter
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033

    Resolved [RESOLVED] [2005] smart tags

    how do you do that in VB 2005 ?

    thx in advance...
    Attached Images Attached Images  

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] smart tags

    What do you mean? If you make your own control?

  3. #3

    Thread Starter
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033

    Re: [2005] smart tags

    Quote Originally Posted by kleinma
    What do you mean? If you make your own control?
    yep... like in this link... but im trying to convert this to vb without success
    http://msdn.microsoft.com/msdnmag/is...signerActions/

  4. #4

    Thread Starter
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033

    Re: [2005] smart tags

    done... http://msdn2.microsoft.com/en-us/library/ms171830.aspx

    for those who need this kind of tags:

    in a Form1

    VB Code:
    1. '///////////////////////////////////////////////////////////////////
    2. 'Pull model smart tag example.
    3. 'Need references to System.dll, System.Windows.Forms.dll,
    4. ' System.Design.dll, and System.Drawing.dll.
    5. '///////////////////////////////////////////////////////////////////
    6. Imports System
    7. Imports System.Drawing
    8. Imports System.Collections
    9. Imports System.ComponentModel
    10. Imports System.ComponentModel.Design
    11. Imports System.Windows.Forms
    12. Imports System.Text
    13. Imports System.Reflection
    14.  
    15. Namespace SmartTags
    16.  
    17.     Public Class Form1
    18.         Inherits System.Windows.Forms.Form
    19.  
    20.  
    21.         Public Sub New()
    22.             InitializeComponent()
    23.         End Sub
    24.  
    25.         'VS Forms Designer generated method
    26.         Private Sub InitializeComponent()
    27.             Me.MyPanel1 = New WindowsApplication1.SmartTags.myPanel
    28.             Me.SuspendLayout()
    29.             '
    30.             'MyPanel1
    31.             '
    32.             Me.MyPanel1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
    33.             Me.MyPanel1.ColorLocked = False
    34.             Me.MyPanel1.Location = New System.Drawing.Point(78, 118)
    35.             Me.MyPanel1.Name = "MyPanel1"
    36.             Me.MyPanel1.Size = New System.Drawing.Size(200, 100)
    37.             Me.MyPanel1.TabIndex = 0
    38.             '
    39.             'Form1
    40.             '
    41.             Me.ClientSize = New System.Drawing.Size(504, 442)
    42.             Me.Controls.Add(Me.MyPanel1)
    43.             Me.Name = "Form1"
    44.             Me.ResumeLayout(False)
    45.  
    46.         End Sub
    47.  
    48.         <STAThread()> _
    49.         Shared Sub Main()
    50.             Dim f1 As New Form1()
    51.             f1.ShowDialog()
    52.         End Sub
    53.         Friend WithEvents MyPanel1 As WindowsApplication1.SmartTags.myPanel
    54.     End Class
    55.  
    56. End Namespace
    Last edited by zuperman; Oct 25th, 2006 at 11:34 AM.

  5. #5

    Thread Starter
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033

    Re: [2005] smart tags

    create a user control, myPanel
    VB Code:
    1. Imports System
    2. Imports System.Drawing
    3. Imports System.Collections
    4. Imports System.ComponentModel
    5. Imports System.ComponentModel.Design
    6. Imports System.Windows.Forms
    7. Imports System.Text
    8. Imports System.Reflection
    9.  
    10. Namespace SmartTags
    11.  
    12.     '///////////////////////////////////////////////////////////////
    13.     'ColorLabel is a simple extension of the standard Label control,
    14.     ' with color property locking added.
    15.     '///////////////////////////////////////////////////////////////
    16.     <Designer(GetType(ColorLabelDesigner))> _
    17.     Public Class myPanel
    18.         Inherits System.Windows.Forms.Panel
    19.  
    20.         Private colorLockedValue As Boolean = False
    21.  
    22.         Public Property ColorLocked() As Boolean
    23.             Get
    24.                 Return colorLockedValue
    25.             End Get
    26.             Set(ByVal value As Boolean)
    27.                 colorLockedValue = value
    28.             End Set
    29.         End Property
    30.  
    31.         Public Overrides Property BackColor() As Color
    32.             Get
    33.                 Return MyBase.BackColor
    34.             End Get
    35.             Set(ByVal value As Color)
    36.                 If ColorLocked Then
    37.                     Return
    38.                 Else
    39.                     MyBase.BackColor = value
    40.                 End If
    41.             End Set
    42.         End Property
    43.  
    44.         Public Overrides Property ForeColor() As Color
    45.             Get
    46.                 Return MyBase.ForeColor
    47.             End Get
    48.             Set(ByVal value As Color)
    49.                 If ColorLocked Then
    50.                     Return
    51.                 Else
    52.                     MyBase.ForeColor = value
    53.                 End If
    54.             End Set
    55.         End Property
    56.     End Class
    57.  
    58.     '///////////////////////////////////////////////////////////////
    59.     'Designer for the ColorLabel control with support for a smart
    60.     ' tag panel.
    61.     '///////////////////////////////////////////////////////////////
    62.     'Must add reference to System.Design.dll
    63.     <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    64.     Public Class ColorLabelDesigner
    65.         Inherits System.Windows.Forms.Design.ControlDesigner
    66.  
    67.         Private lists As DesignerActionListCollection
    68.  
    69.         'Use pull model to populate smart tag menu.
    70.         Public Overrides ReadOnly Property ActionLists() _
    71.         As DesignerActionListCollection
    72.             Get
    73.                 If lists Is Nothing Then
    74.                     lists = New DesignerActionListCollection()
    75.                     lists.Add( _
    76.                     New ColorLabelActionList(Me.Component))
    77.                 End If
    78.                 Return lists
    79.             End Get
    80.         End Property
    81.     End Class
    82.  
    83.     '///////////////////////////////////////////////////////////////
    84.     'DesignerActionList-derived class defines smart tag entries and
    85.     ' resultant actions.
    86.     '///////////////////////////////////////////////////////////////
    87.     Public Class ColorLabelActionList
    88.         Inherits System.ComponentModel.Design.DesignerActionList
    89.  
    90.         Private colLabel As myPanel
    91.  
    92.         Private designerActionUISvc As DesignerActionUIService = Nothing
    93.  
    94.         'The constructor associates the control
    95.         'with the smart tag list.
    96.         Public Sub New(ByVal component As IComponent)
    97.  
    98.             MyBase.New(component)
    99.             Me.colLabel = component
    100.  
    101.             ' Cache a reference to DesignerActionUIService, so the
    102.             ' DesigneractionList can be refreshed.
    103.             Me.designerActionUISvc = _
    104.             CType(GetService(GetType(DesignerActionUIService)), _
    105.             DesignerActionUIService)
    106.  
    107.         End Sub
    108.  
    109.         'Helper method to retrieve control properties. Use of
    110.         ' GetProperties enables undo and menu updates to work properly.
    111.         Private Function GetPropertyByName(ByVal propName As String) _
    112.         As PropertyDescriptor
    113.             Dim prop As PropertyDescriptor
    114.             prop = TypeDescriptor.GetProperties(colLabel)(propName)
    115.             If prop Is Nothing Then
    116.                 Throw New ArgumentException( _
    117.                 "Matching ColorLabel property not found!", propName)
    118.             Else
    119.                 Return prop
    120.             End If
    121.         End Function
    122.  
    123.         'Properties that are targets of DesignerActionPropertyItem entries.
    124.         Public Property BackColor() As Color
    125.             Get
    126.                 Return colLabel.BackColor
    127.             End Get
    128.             Set(ByVal value As Color)
    129.                 GetPropertyByName("BackColor").SetValue(colLabel, value)
    130.             End Set
    131.         End Property
    132.  
    133.         Public Property ForeColor() As Color
    134.             Get
    135.                 Return colLabel.ForeColor
    136.             End Get
    137.             Set(ByVal value As Color)
    138.                 GetPropertyByName("ForeColor").SetValue(colLabel, value)
    139.             End Set
    140.         End Property
    141.  
    142.         'Boolean properties are automatically displayed with binary
    143.         ' UI (such as a checkbox).
    144.         Public Property LockColors() As Boolean
    145.             Get
    146.                 Return colLabel.ColorLocked
    147.             End Get
    148.             Set(ByVal value As Boolean)
    149.                 GetPropertyByName("ColorLocked").SetValue(colLabel, value)
    150.  
    151.                 ' Refresh the list.
    152.                 Me.designerActionUISvc.Refresh(Me.Component)
    153.             End Set
    154.         End Property
    155.  
    156.         'Method that is target of a DesignerActionMethodItem
    157.         Public Sub InvertColors()
    158.             Dim currentBackColor As Color = colLabel.BackColor
    159.             BackColor = Color.FromArgb( _
    160.             255 - currentBackColor.R, _
    161.             255 - currentBackColor.G, _
    162.             255 - currentBackColor.B)
    163.  
    164.             Dim currentForeColor As Color = colLabel.ForeColor
    165.             ForeColor = Color.FromArgb( _
    166.             255 - currentForeColor.R, _
    167.             255 - currentForeColor.G, _
    168.             255 - currentForeColor.B)
    169.         End Sub
    170.  
    171.         'Implementation of this virtual method creates smart tag  
    172.         ' items, associates their targets, and collects into list.
    173.         Public Overrides Function GetSortedActionItems() _
    174.         As DesignerActionItemCollection
    175.             Dim items As New DesignerActionItemCollection()
    176.  
    177.             'Define static section header entries.
    178.             items.Add(New DesignerActionHeaderItem("Appearance"))
    179.             items.Add(New DesignerActionHeaderItem("Information"))
    180.  
    181.             'Boolean property for locking color selections.
    182.             items.Add(New DesignerActionPropertyItem( _
    183.             "LockColors", _
    184.             "Lock Colors", _
    185.             "Appearance", _
    186.             "Locks the color properties."))
    187.  
    188.             If Not LockColors Then
    189.                 items.Add( _
    190.                 New DesignerActionPropertyItem( _
    191.                 "BackColor", _
    192.                 "Back Color", _
    193.                 "Appearance", _
    194.                 "Selects the background color."))
    195.  
    196.                 items.Add( _
    197.                 New DesignerActionPropertyItem( _
    198.                 "ForeColor", _
    199.                 "Fore Color", _
    200.                 "Appearance", _
    201.                 "Selects the foreground color."))
    202.  
    203.                 'This next method item is also added to the context menu
    204.                 ' (as a designer verb).
    205.                 items.Add( _
    206.                 New DesignerActionMethodItem( _
    207.                 Me, _
    208.                 "InvertColors", _
    209.                 "Invert Colors", _
    210.                 "Appearance", _
    211.                 "Inverts the fore and background colors.", _
    212.                 True))
    213.             End If
    214.  
    215.             'Create entries for static Information section.
    216.             Dim location As New StringBuilder("Location: ")
    217.             location.Append(colLabel.Location)
    218.             Dim size As New StringBuilder("Size: ")
    219.             size.Append(colLabel.Size)
    220.  
    221.             items.Add( _
    222.             New DesignerActionTextItem( _
    223.             location.ToString(), _
    224.             "Information"))
    225.  
    226.             items.Add( _
    227.             New DesignerActionTextItem( _
    228.             size.ToString(), _
    229.             "Information"))
    230.  
    231.             Return items
    232.         End Function
    233.  
    234.     End Class
    235.  
    236. End Namespace

    Regards...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width