2009-08-15 32 views
6

Nhìn vào hình ảnh sau đây, được hiển thị một thẻ thông minh cho DataGridView.Làm cách nào để thêm thẻ thông minh vào thành phần .NET của tôi?

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

Bây giờ tôi đang tạo ra một thành phần mới, và tôi muốn nó hỗ trợ hiển thị một số thuộc tính trong thẻ thông minh. Làm cách nào để thêm thuộc tính vào thẻ thông minh?

+1

Đó là một chủ đề lớn. Thành phần của bạn có hỗ trợ thiết kế nào ngay bây giờ không? –

+0

Cảm ơn, để đơn giản hóa câu hỏi, hãy cho chúng tôi biết rằng tôi có hộp văn bản số và tôi muốn thêm thuộc tính số cho phép/vô hiệu hóa vào thẻ thông minh. –

+1

Cảm ơn * bạn *, nhưng điều đó không trả lời được câu hỏi của tôi. Thành phần của bạn hiện có hỗ trợ thiết kế không? –

Trả lời

2

Bạn có thể sử dụng mã sau để xem thẻ mẫu trong điều khiển tùy chỉnh.

Và bạn có thể xem video về điều đó từ 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

Tôi đã sử dụng http://msdn.microsoft.com/en-us/library/default.aspx?q=smart+tag+windows+forms+designer.

Kết quả là tôi đã tìm thấy Walkthrough: Adding Smart Tags to a Windows Forms Component.

Bất kỳ ai thực hiện cùng một tìm kiếm cũng sẽ tìm thấy cùng một bài viết.


Cập nhật: Liên kết đó không còn hoạt động nữa. Tôi vừa thử tìm kiếm "smart tag windows forms designer" và đã tìm thấy "Walkthrough: Adding Smart Tags to a Windows Forms Component" làm lần truy cập tìm kiếm đầu tiên. Tìm kiếm tương tự trong Google hiển thị "How to: Attach Smart Tags to a Windows Forms Component" là lần truy cập đầu tiên, nhưng hiển thị cùng một Hướng dẫn như lần truy cập thứ hai.

+2

Ồ, thôi nào! Có phải các downvotes cho thấy anh ta dành hai phút giống như tôi đã làm? –

+2

-1 Rất không hữu ích và tăng dần. – Pwninstein

+7

Có. Hãy suy nghĩ về nó từ quan điểm của người hỏi - có * cách * nhiều giá trị hơn trong việc dành 30 giây để đặt một câu hỏi trước hàng ngàn chuyên gia hơn 2 phút mà có thể hoặc không thể giúp được gì. Đó là những gì chúng tôi đang ở đây. Rudeness làm mất đi một câu trả lời hữu ích. –

Các vấn đề liên quan