![](/img/trans.png)
[英]How can I create WPF User Control as dll and then see it in another WPF application?
[英]How can i create a dll of a User Control in a win forms project?
我在我的项目中创建了这个用户控件。 当我编译项目时,我看到了项目 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 窗体控件库类型的项目,将您的用户控件添加到该项目中。 它的输出是类型类库。 编译后,您可以通过右键单击并选择“选择项目”并浏览到 dll 的位置将其添加到您的工具箱中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.