C# 为什么从类库项目i';m获取错误:错误提供程序1上的错误?
我使用此网站作为在本案例文本框中创建自定义控件的示例: 在类库项目中,我构建了该项目,并拥有dll文件。 然后,在我的Windows窗体项目中的Take框中,当我选择dll文件时,我确实选择了项,我看到它已添加到dll文件列表中,但在它附近我没有看到这个紫色标志: 这是添加dll文件时windows窗体项目的屏幕截图 在左边,加载后的dll名为:ExtdTextBox,但在它的左边附近,没有这个紫色符号 然后在form1设计器中,拖动文本框后,您将看到它 在底部解决方案资源管理器的右侧,您可以看到我得到的错误: ErrorProvider1上出现错误 这是我添加到类库项目中的类:C# 为什么从类库项目i';m获取错误:错误提供程序1上的错误?,c#,.net,winforms,C#,.net,Winforms,我使用此网站作为在本案例文本框中创建自定义控件的示例: 在类库项目中,我构建了该项目,并拥有dll文件。 然后,在我的Windows窗体项目中的Take框中,当我选择dll文件时,我确实选择了项,我看到它已添加到dll文件列表中,但在它附近我没有看到这个紫色标志: 这是添加dll文件时windows窗体项目的屏幕截图 在左边,加载后的dll名为:ExtdTextBox,但在它的左边附近,没有这个紫色符号 然后在form1设计器中,拖动文本框后,您将看到它 在底部解决方案资源管理器的右侧,您可
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
namespace CustomControl
{
public class ExtdTextBox : TextBox
{
#region Member Variables
Color waterMarkColor = Color.Gray;
Color forecolor;
Font font;
Font waterMarkFont;
string waterMarkText = "Your Text Here";
#endregion
#region Constructor
public ExtdTextBox()
{
base.Text = this.waterMarkText;
this.forecolor = this.ForeColor;
this.ForeColor = this.waterMarkColor;
this.font = this.Font;
//event handlers
this.TextChanged += new EventHandler(ExtdTextBox_TextChanged);
this.KeyPress += new KeyPressEventHandler(ExtdTextBox_KeyPress);
this.LostFocus += new EventHandler(ExtdTextBox_TextChanged);
}
#endregion
#region Event Handler Methods
void ExtdTextBox_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.Text))
{
this.ForeColor = this.forecolor;
this.Font = this.font;
}
else
{
this.TextChanged -= new EventHandler(ExtdTextBox_TextChanged);
base.Text = this.waterMarkText;
this.TextChanged += new EventHandler(ExtdTextBox_TextChanged);
this.ForeColor = this.waterMarkColor;
this.Font = this.waterMarkFont;
}
}
void ExtdTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
string str = base.Text.Replace(this.waterMarkText, "");
this.TextChanged -= new EventHandler(ExtdTextBox_TextChanged);
this.Text = str;
this.TextChanged += new EventHandler(ExtdTextBox_TextChanged);
}
#endregion
#region User Defined Properties
/// <summary>
/// Property to set/get Watermark color at design/runtime
/// </summary>
[Browsable(true)]
[Category("Extended Properties")]
[Description("sets Watermark color")]
[DisplayName("WaterMark Color")]
public Color WaterMarkColor
{
get
{
return this.waterMarkColor;
}
set
{
this.waterMarkColor = value;
base.OnTextChanged(new EventArgs());
}
}
[Browsable(true)]
[Category("Extended Properties")]
[Description("sets TextBox text")]
[DisplayName("Text")]
/// <summary>
/// Property to get Text at runtime(hides base Text property)
/// </summary>
public new string Text
{
get
{
//required for validation for Text property
return base.Text.Replace(this.waterMarkText, string.Empty);
}
set
{
base.Text = value;
}
}
[Browsable(true)]
[Category("Extended Properties")]
[Description("sets WaterMark font")]
[DisplayName("WaterMark Font")]
/// <summary>
/// Property to get Text at runtime(hides base Text property)
/// </summary>
public Font WaterMarkFont
{
get
{
//required for validation for Text property
return this.waterMarkFont;
}
set
{
this.waterMarkFont = value;
this.OnTextChanged(new EventArgs());
}
}
/// <summary>
/// Property to set/get Watermark text at design/runtime
/// </summary>
[Browsable(true)]
[Category("Extended Properties")]
[Description("sets Watermark Text")]
[DisplayName("WaterMark Text")]
public string WaterMarkText
{
get
{
return this.waterMarkText;
}
set
{
this.waterMarkText = value;
base.OnTextChanged(new EventArgs());
}
}
#endregion
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用系统组件模型;
使用系统图;
命名空间自定义控件
{
公共类ExtdTextBox:TextBox
{
#区域成员变量
颜色水印颜色=颜色。灰色;
彩色前景色;
字体;
字体水印字体;
字符串waterMarkText=“此处的文本”;
#端区
#区域构造函数
公共ExtdTextBox()
{
base.Text=this.waterMarkText;
this.forecolor=this.forecolor;
this.ForeColor=this.waterMarkColor;
this.font=this.font;
//事件处理程序
this.TextChanged+=新事件处理程序(ExtdTextBox\u TextChanged);
this.KeyPress+=新的KeyPressEventHandler(ExtdTextBox\u KeyPress);
this.LostFocus+=新的事件处理程序(ExtdTextBox\u TextChanged);
}
#端区
#区域事件处理程序方法
void ExtdTextBox_TextChanged(对象发送方,事件参数e)
{
如果(!string.IsNullOrEmpty(this.Text))
{
this.ForeColor=this.ForeColor;
this.Font=this.Font;
}
其他的
{
this.TextChanged-=新事件处理程序(ExtdTextBox\u TextChanged);
base.Text=this.waterMarkText;
this.TextChanged+=新事件处理程序(ExtdTextBox\u TextChanged);
this.ForeColor=this.waterMarkColor;
this.Font=this.waterMarkFont;
}
}
void ExtdTextBox_按键(对象发送器,按键事件参数e)
{
字符串str=base.Text.Replace(this.waterMarkText,“”);
this.TextChanged-=新事件处理程序(ExtdTextBox\u TextChanged);
this.Text=str;
this.TextChanged+=新事件处理程序(ExtdTextBox\u TextChanged);
}
#端区
#区域用户定义属性
///
///属性在设计/运行时设置/获取水印颜色
///
[可浏览(正确)]
[类别(“扩展属性”)]
[说明(“设置水印颜色”)]
[显示名称(“水印颜色”)]
公共颜色水印颜色
{
得到
{
返回此.waterMarkColor;
}
设置
{
this.waterMarkColor=值;
contextChanged(新的EventArgs());
}
}
[可浏览(正确)]
[类别(“扩展属性”)]
[说明(“设置文本框文本”)]
[显示名称(“文本”)]
///
///属性在运行时获取文本(隐藏基本文本属性)
///
公共新字符串文本
{
得到
{
//验证文本属性时需要此选项
返回base.Text.Replace(this.waterMarkText,string.Empty);
}
设置
{
base.Text=值;
}
}
[可浏览(正确)]
[类别(“扩展属性”)]
[说明(“设置水印字体”)]
[显示名称(“水印字体”)]
///
///属性在运行时获取文本(隐藏基本文本属性)
///
公共字体水印字体
{
得到
{
//验证文本属性时需要此选项
返回此.waterMarkFont;
}
设置
{
this.waterMarkFont=值;
this.OnTextChanged(新的EventArgs());
}
}
///
///属性在设计/运行时设置/获取水印文本
///
[可浏览(正确)]
[类别(“扩展属性”)]
[说明(“设置水印文本”)]
[显示名称(“水印文本”)]
公共字符串水印文本
{
得到
{
返回此.waterMarkText;
}
设置
{
this.waterMarkText=值;
contextChanged(新的EventArgs());
}
}
#端区
}
}
类库项目类似于我在c#>windows>windows窗体控件库下创建的新项目的网站示例
.net 4.5由于我要将dll添加到的windows窗体项目也是.net 4.5,因此这不是一个错误;它是组件提供的名为
Error
的属性。此组件允许您将错误消息与任何控件关联