编写控件提示“不包含任何 UserControl 类型”

AlloverJandy 2009-05-04 09:36:22
小弟新手,今天照着网上了一篇教程写控件,编译时提示:
“程序集“e:\vscsharp\ControlButton\LinearGradientButtonLib\LinearGradientButtonLib\obj\Debug\LinearGradientButtonLib.dll”不包含任何 UserControl 类型。”

望高手解答

文件LinearGradientButton.cs 中代码为:
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;
using System.Drawing.Drawing2D;

namespace LinearGradientButtonLib
{
public partial class LinearGradientButton : System.Windows.Forms.Button
{
private Color froColor; //渐变前景色

private Color backColor;//渐变背景色

private bool isUseFloat;//是否使用角度转变

private float angle; //放置角度

private LinearGradientMode mode;//设定渐变的角度

private HatchStyle hatchStyle; //设定文本的填充图案

private bool isUseStyle;//设定是否用图案填充图案

[Description("设定按钮渐变的前景色"), Category("Appearance")]

public Color FrontColor
{

get
{

return froColor;

}

set
{

froColor = value;

}

}

[Description("设定按钮渐变的背景色"), Category("Appearance")]

public Color BackGroundColor
{

get
{

return backColor;

}

set
{

backColor = value;

}

}

[DefaultValue(false), Description("设定是否人工设定角度")]

public bool UseFloat
{

get
{

return isUseFloat;

}

set
{

isUseFloat = value;

}

}

[DefaultValue(false), Description("设定是否使用图案填充文本")]

public bool UseStyle
{

get
{

return isUseStyle;

}

set
{

isUseStyle = value;

}

}

[DefaultValue(0), Description("定义渐变方向的角度,以度为单位从 X 轴顺时针测量。 "), Category("Appearance")]

public float Angle
{

get
{

return angle;

}

set
{

angle = value;

}

}

[DefaultValue(0), Description("当UseFloat设为false时,设定渐变方向。 "), Category("Appearance")]

public LinearGradientMode Mode
{

get
{

return mode;

}

set
{

mode = value;

}

}

[DefaultValue(false), Description("设定文本要填充的图案"), Category("Appearance")]

public HatchStyle FillStyle
{

get
{

return hatchStyle;

}

set
{

hatchStyle = value;

}

}

//使用角度的方法渐近重画Button

private void DrawButtonWithAngle(Graphics dbg)
{

LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), froColor, backColor, angle);

dbg.FillRectangle(brush, 0, 0, this.Width, this.Height);

brush.Dispose();

}

////使用模式的方法渐近重画Button

private void DrawButtonWithMode(Graphics dbg, LinearGradientMode Mode)
{

LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), froColor, backColor, Mode);

dbg.FillRectangle(brush, 0, 0, this.Width, this.Height);

brush.Dispose();

}

//重画Button的文本(Text),不使用图案填充

private void DrawButtonText(Graphics dbg)
{

StringFormat format = new StringFormat();

format.LineAlignment = StringAlignment.Center;

format.Alignment = StringAlignment.Center;

dbg.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), new Rectangle(0, 0, this.Width, this.Height), format);

}

//override DrawButtonText函数,使之可以用图案填充文本

private void DrawButtonText(Graphics dbg, HatchStyle hs)
{

StringFormat format = new StringFormat();

format.LineAlignment = StringAlignment.Center;

format.Alignment = StringAlignment.Center;

dbg.DrawString(this.Text, this.Font, new HatchBrush(hs, this.ForeColor, Color.Aquamarine), new Rectangle(0, 0, this.Width, this.Height), format);

}
protected override void OnPaint(PaintEventArgs pe)
{



Graphics g = pe.Graphics;

base.OnPaint(pe); //调用父控件的方法

if (isUseFloat == true) //假如使用角度控制渐变的角度

DrawButtonWithAngle(g);

if (isUseFloat == false)

DrawButtonWithMode(g, mode);

if (isUseStyle == true)//假如使用图案填充文字

DrawButtonText(g, hatchStyle);

else

DrawButtonText(g);

}
public LinearGradientButton()
{
InitializeComponent();
}
}
}

文件 LinearGradientButtonDesigner.cs中的代码为:
namespace LinearGradientButtonLib
{
partial class LinearGradientButton
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region 组件设计器生成的代码

/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
//this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}

#endregion
}
}

...全文
932 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
elecwave 2009-12-16
  • 打赏
  • 举报
回复 1
你可能是把启动项设成了控件的项目,检查一下解决方案的启动项,要设为可运行的项目(含有Form窗体的)。
AlloverJandy 2009-05-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 yagebu1983 的回复:]
UserControl是用来定义用户控件的。。。
[/Quote]

阁下能否说详细点?
AlloverJandy 2009-05-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wuyq11 的回复:]
写控件,生成DLL文件
参考
参考
[/Quote]
恕我愚钝,还是没有弄明白
wuyq11 2009-05-04
  • 打赏
  • 举报
回复
写控件,生成DLL文件
参考
参考
yagebu1983 2009-05-04
  • 打赏
  • 举报
回复
UserControl是用来定义用户控件的。。。
AlloverJandy 2009-05-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 uncleson88 的回复:]
代码完全没问题呀?不知道是怎么回事~~~~
帮顶
[/Quote]
谢谢啊,继续等解答
uncleson88 2009-05-04
  • 打赏
  • 举报
回复
代码完全没问题呀?不知道是怎么回事~~~~
帮顶
llsen 2009-05-04
  • 打赏
  • 举报
回复
up

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧