【发布时间】:2014-11-12 18:12:13
【问题描述】:
我有一个库类,我添加了一个新的用户控件并添加了一个代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomControl
{
public partial class ExtendedTextBox : UserControl
{
[PropertyTab("Data")]
[Browsable(true)]
[Category("Extended Properties")]
[Description("Set TextBox border Color")]
public string Texts
{
get { return textBox.Text; }
set { textBox.Text = value; }
}
private TextBox textBox;
public ExtendedTextBox()
{
InitializeComponent();
textBox = new TextBox();
textBox.Multiline = true;
textBox.BorderStyle = BorderStyle.None;
this.Controls.Add(textBox);
}
private void ExtendedTextBox_Load(object sender, EventArgs e)
{
}
private void ExtendedTextBox_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
}
private void ExtendedTextBox_Resize(object sender, EventArgs e)
{
textBox.Size = new Size(this.Width - 3, this.Height - 2);
textBox.Location = new Point(2, 1);
}
}
}
当我将 dll 文件添加到另一个 windows 窗体项目时,我将控件拖到设计器中,但在解决方案资源管理器中的控件属性下,我看不到数据,也看不到扩展属性,也没有设置文本框边框颜色。
我想添加一个属性,当您单击它时会为您提供一个子属性,单击该属性将打开颜色模式,以便您可以更改/设置绘画事件的新颜色。
现在在绘制事件中它设置为红色,但我希望有一个属性,以便用户可以设置任何颜色。
【问题讨论】: