0
我想創建一個控件,在類庫項目中繪製一個表格,並將此dll添加到工具箱中,並在Windows窗體應用程序中使用它。我嘗試和谷歌搜索,但我找不到。 我該怎麼辦?如何在Visual Studio 2015中創建自定義控件並將其添加到工具箱
我在類庫項目
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace ClassLibrary1
{
class PanelZ : System.Windows.Forms.Panel
{
private Color color1 = Color.SteelBlue;
private Color color2 = Color.DarkBlue;
private int color1Transparent = 150;
private int color2Transparent = 150;
private int angle = 90;
public Color StartColor
{
get { return color1; }
set { color1 = value; Invalidate(); }
}
public Color EndColor
{
get { return color2; }
set { color2 = value; Invalidate(); }
}
public int Transparent1
{
get { return color1Transparent; }
set
{
color1Transparent = value;
if (color1Transparent > 255)
{
color1Transparent = 255;
Invalidate();
}
else
Invalidate();
}
}
public int Transparent2
{
get { return color2Transparent; }
set
{
color2Transparent = value;
if (color2Transparent > 255)
{
color2Transparent = 255;
Invalidate();
}
else
Invalidate();
}
}
public int GradientAngle
{
get { return angle; }
set { angle = value; Invalidate(); }
}
public PanelZ()
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Color c1 = Color.FromArgb(color1Transparent, color1);
Color c2 = Color.FromArgb(color2Transparent, color2);
Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle, c1, c2, angle);
e.Graphics.FillRectangle(b, ClientRectangle);
b.Dispose();
}
}
}
創建此類但是當我添加MYDLL到工具箱中我得到這個錯誤 image here
我可以在類庫項目中創建它,並將此dll添加到工具箱? – zfarzaneh
如果它們在單獨的解決方案中,則可以使用工具箱中的右鍵單擊菜單,選擇「選擇項目」並瀏覽到DLL,將其添加到工具箱中。 –
我更新了答案,指出錯誤的原因。它需要是一個「公共」控制 –