[英]Why when adding dll file from Class Library project i'm getting error: Error on error Provider1?
我使用此網站作為在這種情況下的textBox中創建自定義控件的示例:
在類庫項目中,我構建了項目,並且擁有dll文件。 然后在我的Windows Forms項目中,在Take框上,當我選擇dll文件時我確實選擇了項目,我看到它已添加到dll文件列表中,但我看不到它附近的這個紫色標志:
這是添加dll文件時Windows窗體項目的屏幕截圖。
加載后的dll左側為:ExtdTextBox,但靠近它的左側沒有此紫色符號。
然后,在form1設計器中,拖動后會看到文本框。
在底部的解決方案資源管理器的右側,您會看到我得到的錯誤:
errorProviler1上的錯誤
這是我添加到“類庫”項目中的類:
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
}
}
類庫項目就像在網站示例中一樣,我在c#> Windows> Windows窗體控件庫下創建了新項目
.net 4.5,因為我的Windows窗體項目我也想將dll添加到.net 4.5
這不是錯誤; 它是由ErrorProvider
組件提供的名為Error
的屬性。 該組件使您可以將錯誤消息與任何控件相關聯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.