Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i create a dll of a User Control in a win forms project?

Tags:

c#

I have this user control i created in my project. When i compile the project i see the project dll. But how can i make that when i compile the project it will create also a dll of the User Control so later on other project i will be able to add this User Control dll to my tool box ?

/*----------------------------------------------------------------
 * 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);
            }
        }
    }
}
like image 524
user1196715 Avatar asked Dec 30 '12 03:12

user1196715


1 Answers

You will need to create a separate Project of Type Windows Forms Control Library add your UserControls to that. It's output is of Type Class Library. Once you compile it you can add it to your ToolBox by right clicking and selecting Choose Items and browsing to the dll's location.

like image 79
Mark Hall Avatar answered Nov 16 '22 00:11

Mark Hall