Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add smart tags to my .NET component?

Look at the following picture, which is showing a smart tag for DataGridView.

DataGridView Smart Tags http://img199.imageshack.us/img199/5871/post517531249536112.jpg

Now I'm creating a new component, and I want it to support showing some properties in smart tags. How do I add the properties to the smart tag?

like image 906
Wael Dalloul Avatar asked Aug 15 '09 13:08

Wael Dalloul


People also ask

Where do you use Smart Tags?

You can also use Smart Tags in your Outlook e-mail messages and in Microsoft Excel. You can use Smart Tags to perform actions in Microsoft Word that you would normally start other programs to do. The purple dotted lines beneath text in your document indicate Smart Tags.

How do I enable smart tags in outlook?

Click Tools > Options > Other. 3. In the Person Names section, click the Enable Person Names Smart Tag.

What is smart tag in Visual Studio?

Last Updated on Wed, 06 Jan 2021. Visual Studio 2005 includes a new feature for creating a rich design-time experience—smart tags. Smart tags are the pop-up windows that appear next to a control when you click the tiny arrow in the corner. Smart tags are similar to menus in that they have a list of items.

What is access smart tag?

Smart tags allow administrators to group emails and files together in folders. These can then be made available to users via the Mimecast Personal Portal or Mimecast for Outlook. Once users have access to smart tag messages, they can forward them to additional recipients, but they can't modify or delete them.


2 Answers

I used http://msdn.microsoft.com/en-us/library/default.aspx?q=smart+tag+windows+forms+designer.

As a result, I found Walkthrough: Adding Smart Tags to a Windows Forms Component.

Anyone who does the same search will find the same article.


Update: That link no longer works. I just tried a search for "smart tag windows forms designer", and found "Walkthrough: Adding Smart Tags to a Windows Forms Component" as the first search hit. The same search in Google shows "How to: Attach Smart Tags to a Windows Forms Component" as the first hit, but shows the same Walkthrough as the second hit.

like image 133
John Saunders Avatar answered Oct 09 '22 20:10

John Saunders


You can use the following code to view a sample tag in a custom control.

And you can get a video about that from www.windowsclient.com.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel.Design;
namespace MakeSmartTag
{
    public enum Languages
    {
        English,
        Arabic,
        Japanese
    }

    [Designer(typeof(UserControlDesigner))]
    public partial class UserControl2 : UserControl
    {
        public UserControl2()
        {
            InitializeComponent();
        }

        private Languages _language;

        public Languages Language
        {
            get { return _language; }
            set
            {
                switch (value)
                {
                    case Languages.Arabic:
                        {
                            label1.Text = "مرحباً";
                            _language = value;
                        }
                        break;
                    case Languages.English:
                        {
                            label1.Text = "Hello";
                            _language = value;
                        }
                        break;
                    case Languages.Japanese:
                        {
                            label1.Text = "Conechoa";
                            _language = value;
                        }
                        break;
                }
            }
        }
    }

    public class UserControlDesigner : System.Windows.Forms.Design.ControlDesigner
    {
        private DesignerActionListCollection lists;
        public override DesignerActionListCollection ActionLists
        {
            get
            {
                if (lists == null)
                {

                    lists = new DesignerActionListCollection();
                    lists.Add(new UserControlActioonList(this.Component));
                }
                return lists;
            }
        }
    }

    public class UserControlActioonList : DesignerActionList
    {
        private UserControl2 myUserControl;
        private DesignerActionUIService designerActionSvc = null;

        public UserControlActioonList(IComponent component)
            : base(component)
        {
            this.myUserControl = (UserControl2)component;

            this.designerActionSvc =
              (DesignerActionUIService)GetService(typeof(DesignerActionUIService));
        }

        private PropertyDescriptor GetPropertyByName(string propName)
        {
            PropertyDescriptor prop = default(PropertyDescriptor);
            prop = TypeDescriptor.GetProperties(myUserControl)[propName];
            if (prop == null)
            {
                throw new ArgumentException("Invalid Property", propName);
            }
            else
            {
                return prop;
            }
        }

        public override System.ComponentModel.Design.DesignerActionItemCollection GetSortedActionItems()
        {
            DesignerActionItemCollection item = new DesignerActionItemCollection();
            item.Add(new DesignerActionHeaderItem(
                       "المظهر"));
            item.Add(new DesignerActionPropertyItem(
                       "BackColor", "لون الخلفية", "Appearance", "Set background Color of the control"));
            item.Add(new DesignerActionHeaderItem("تحديد اللغة"));
            item.Add(new DesignerActionPropertyItem(
                       "Language", "اللغة", "Functions", "Set the language of the control"));
            return item;
        }

        public Color BackColor
        {
            get { return this.myUserControl.BackColor; }
            set { GetPropertyByName("BackColor").SetValue(myUserControl, value); }
        }

        public Languages Language
        {
            get { return this.myUserControl.Language; }
            set { GetPropertyByName("Language").SetValue(myUserControl, value); }
        }
    }
}
like image 28
Belal mazlom Avatar answered Oct 09 '22 21:10

Belal mazlom