微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 如何在win表单项目中创建用户控件的dll?

我在我的项目中创建了这个用户控件.
当我编译项目时,我看到项目DLL.
但是,当我编译项目时,我怎么能创建它还会创建一个用户控件的DLL,所以稍后在其他项目上我将能够将此用户控件dll添加到我的工具箱?
/*----------------------------------------------------------------
 * 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);
            }
        }
    }
}

解决方法

您将需要创建一个单独的项目类型 Windows Forms Control Library添加您的UserControls.它的输出是Type Class Library.编译完成后,可以通过右键单击并选择“选择项目”并浏览到dll的位置将其添加到ToolBox中.

原文地址:https://www.jb51.cc/csharp/243413.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐