using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsFormsApplication1
{
[ToolboxItem(true)]
public partial class TextBoxLine : TextBox
{
public TextBoxLine()
{
InitializeComponent();
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.BorderStyle = BorderStyle.None;
}
public TextBoxLine(IContainer container)
{
container.Add(this);
InitializeComponent();
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.BorderStyle = BorderStyle.None;
}
private bool m_DrawLine = false;
public bool DrawLine
{
get
{
return this.m_DrawLine;
}
set
{
this.m_DrawLine = value;
this.Invalidate();
}
}
private Color _linecolor = Color.Black;
/// <summary>
/// 线条颜色
/// </summary>
public Color LineColor
{
get
{
return this._linecolor;
}
set
{
this._linecolor = value;
this.Invalidate();
}
}
[System.Runtime.InteropServices.DllImport("user32.dll ")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[System.Runtime.InteropServices.DllImport("user32.dll ")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0xf || m.Msg == 0x133)
{
if (this.DrawLine)
{
IntPtr hDC = GetWindowDC(m.HWnd);
if (hDC.ToInt32() == 0)
{
return;
}
Graphics g = Graphics.FromHdc(hDC);
Pen p = new Pen(this._linecolor, 1);
Point p1 = new Point(0, this.Height - 1);
Point p2 = new Point(this.Width, Height - 1);
g.DrawLine(p, p1, p2);
m.Result = IntPtr.Zero;
ReleaseDC(m.HWnd, hDC);
}
}
}
}
}
原文地址:http://blog.csdn.net/geovi/article/details/7399406
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。