8,834
社区成员
发帖
与我相关
我的任务
分享
private void DrawLine()
{
Graphics g = this.CreateGraphics();
using (SolidBrush b = new SolidBrush(Color.White))
{
if(this.Focused!=true)
g.FillRectangle(b, new Rectangle(_unvisibleWidth, 0, this.Width,this.Height));
}
}
public partial class LengthTextBox : TextBox
{
public LengthTextBox()
{
this.Width = 100;
}
private int _unvisibleWidth = 50;
/// <summary>
/// 开始不显示的长度
/// </summary>
public int UnVisibleWidth
{
get
{
return this._unvisibleWidth;
}
set
{
this._unvisibleWidth = value;
this.Invalidate();
}
}
private const int WM_PAINT = 0xF;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_PAINT)
{
DrawLine();
}
}
private void DrawLine()
{
Graphics g = this.CreateGraphics();
using (SolidBrush b = new SolidBrush(Color.White))
{
g.FillRectangle(b, new Rectangle(_unvisibleWidth, 0, this.Width,this.Height));
}
}
}