c# – 如何在win表单项目中创建用户控件的dll?
发布时间:2020-12-15 08:23:50  所属栏目:百科  来源:网络整理 
            导读:我在我的项目中创建了这个用户控件. 当我编译项目时,我看到项目DLL. 但是,当我编译项目时,我怎么能创建它还会创建一个用户控件的DLL,所以稍后在其他项目上我将能够将此用户控件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中.
 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 
相关内容
- swfupload + commons-fileupload实现文件批量上传,带百分比
- Vue实例中生命周期created和mounted的区别详解
- 尝试使用Ruby Java Bridge(RJB)gem时出错“无法创建Java VM
- ios – Xcode 9 beta新版本系统因“无法构建节点”错误而失
- c# – System.Diagnostics.Debugger.Debug()停止工作
- c – 是否可以在Win32编辑控件中突出显示文本?
- Oracle中使用DBMS_XPLAN处理执行计划详解
- c# – 遍历html字符串以查找所有img标记并替换src属性值
- Ajax再回首
- 处理PostgreSQL Transactoin in Read Only Mode一例
