2009-08-15 10 views
6

Mire la siguiente imagen, que muestra una etiqueta inteligente para DataGridView.¿Cómo agregar etiquetas inteligentes a mi componente .NET?

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

Ahora estoy creando un nuevo componente, y quiero que soporte mostrando algunas propiedades de las etiquetas inteligentes. ¿Cómo agrego las propiedades a la etiqueta inteligente?

+1

Eso es un gran tema. ¿Su componente tiene soporte de diseñador ahora mismo? –

+0

Gracias, para simplificar la pregunta, digamos que tengo un cuadro de texto numérico, y quiero agregar la propiedad habilitar/deshabilitar numérica a la etiqueta inteligente. –

+1

Gracias * usted *, pero eso no respondió mi pregunta. ¿Su componente actualmente tiene soporte de diseñador? –

Respuesta

2

Puede usar el siguiente código para ver una etiqueta de muestra en un control personalizado.

Y puede obtener un video al respecto desde 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); } 
     } 
    } 
} 
5

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

Como resultado, encontré Walkthrough: Adding Smart Tags to a Windows Forms Component.

Cualquiera que haga la misma búsqueda encontrará el mismo artículo.


Actualización: Ese enlace ya no funciona. Intenté una búsqueda para "smart tag windows forms designer", y encontré "Walkthrough: Adding Smart Tags to a Windows Forms Component" como el primer golpe de la búsqueda. La misma búsqueda en Google muestra "How to: Attach Smart Tags to a Windows Forms Component" como primer golpe, pero muestra el mismo Tutorial que el segundo golpe.

+2

¡Oh, vamos! ¿Están los votos a favor por sugerir que él pase los mismos dos minutos que yo? –

+2

-1 Muy poco útil y condescendiente. – Pwninstein

+7

Sí. Piénselo desde el punto de vista del consultante: hay * más valor * en pasar 30 segundos planteando una pregunta a miles de expertos que en 2 minutos que pueden o no dar ninguna ayuda. Es para lo que estamos aquí. La grosería resta valor a una respuesta útil. –

Cuestiones relacionadas