2012-12-30 33 views
6

Tôi có điều khiển người dùng này mà tôi đã tạo trong dự án của mình. Khi tôi biên dịch dự án, tôi thấy dự án dll. Nhưng làm thế nào tôi có thể làm điều đó khi tôi biên dịch dự án nó sẽ tạo ra một dll của User Control để sau này trên dự án khác tôi sẽ có thể thêm dll User Control này vào hộp công cụ của tôi?Làm cách nào để tạo một dll của Điều khiển người dùng trong dự án biểu mẫu giành chiến thắng?

/*---------------------------------------------------------------- 
* Module Name : ListBoxControl 
* Description : Change listBox items color 
* Author  : Danny 
* Date   : 30/12/2012 
* Revision  : 1.00 
* --------------------------------------------------------------*/ 

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Drawing; 
using System.Data; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

/* 
* Introduction : 
* 
* By default the color is red. 
* Added a property to change the color. 
* Right mouse click on item to change item color. 
* Left mouse click on item to change the item color back. 
* */ 

namespace ListBoxControl 
{ 
    public partial class ListBoxControl : UserControl 
    { 
     Color m_MyListColor; 
     private List<int> m_itemIndexes = new List<int>(); 

     public ListBoxControl() 
     { 
      InitializeComponent(); 

      for (int i = 0; i < 10; i++) 
      { 
       listBox1.Items.Add("Test " + i); 
      } 
     } 

     private void listBox1_MouseDown(object sender, MouseEventArgs e) 
     { 
      int index = listBox1.IndexFromPoint(e.X, e.Y); 
      listBox1.SelectedIndex = index; 

      if (e.Button == System.Windows.Forms.MouseButtons.Right) 
      { 
       if (m_itemIndexes.Contains(index)) 
        return; 

       m_itemIndexes.Add(index); 
       DrawItem(index); 
      } 
      else if (e.Button == MouseButtons.Left) 
      { 
       if (!m_itemIndexes.Contains(index)) 
        return; 

       m_itemIndexes.Remove(index); 
       DrawItem(index); 
      } 
     } 
    } 
} 
+0

Một lời khuyên, không đưa ra một lớp (hoặc bất kỳ loại nào cho vấn đề đó) và một không gian tên có cùng tên. –

Trả lời

9

Bạn sẽ cần phải tạo một Dự án riêng biệt loại Windows Forms Control Library thêm UserControls của bạn vào đó. Đầu ra của nó là thư viện kiểu lớp. Một khi bạn biên dịch nó, bạn có thể thêm nó vào ToolBox của bạn bằng cách kích chuột phải và chọn Choose Items và duyệt đến vị trí của dll.

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