2009-08-15 15 views
6

DataGridViewのスマートタグを表示している次の画像を見てください。.NETコンポーネントにスマートタグを追加する方法は?

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

今、私は新しいコンポーネントを作成しています、と私はそれがスマートタグでのいくつかの性質を示すサポートしたいです。スマートタグにプロパティを追加するにはどうすればよいですか?

+1

。あなたのコンポーネントは今、デザイナーのサポートを受けていますか? –

+0

質問を簡略化するために、数値のテキストボックスがあり、スマートタグに有効/無効数値プロパティを追加したいとします。 –

+1

ありがとうございました*しかし、それは私の質問に答えませんでした。あなたのコンポーネントは現在デザイナーのサポートを受けていますか? –

答えて

2

次のコードを使用すると、カスタムコントロールのサンプルタグを表示できます。

そして、そのビデオは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

http://msdn.microsoft.com/en-us/library/default.aspx?q=smart+tag+windows+forms+designerを使用しました。

この結果、Walkthrough: Adding Smart Tags to a Windows Forms Componentが見つかりました。

同じ検索を行う人は同じ記事を見つけるでしょう。


更新:そのリンクはもう機能しません。私はちょうど"smart tag windows forms designer"のための調査を試み、最初の調査のヒットとして"Walkthrough: Adding Smart Tags to a Windows Forms Component"を見つけた。 Googleの同じ検索では、最初のヒットとして"How to: Attach Smart Tags to a Windows Forms Component"が表示されますが、2回目のヒットと同じウォークスルーが表示されます。

+2

ああ、来て!彼は私がしたのと同じ2分を過ごすことを示唆するためのdownvotesですか? –

+2

-1非常に役に立たず、納得がいかない。 – Pwninstein

+7

はい。質問者の視点から考えてみましょう - 30秒間に何千人もの専門家の前に質問を投げかけて2分以上かかると、どんな助けも得られないかもしれません。それは私たちがここにいるのです。 Rudenessは他に役立つ答えから減ります。 –

関連する問題