/// <summary>
/// 只显示下边框的TextBox控件
/// </summary>
public class BottomTextBox : TextBox
{
/// <summary>
/// 获得当前进程,以便重绘控件
/// </summary>
/// <param name="hWnd"></param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
/// <summary>
/// 释放控件
/// </summary>
/// <param name="hWnd"></param>
/// <param name="hDC"></param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
/// <summary>
/// 重绘TextBox
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
try
{
if (m.Msg != 0xf && m.Msg != 0x133)
{
return;
}
IntPtr hDC = GetWindowDC(m.HWnd);
if (hDC.ToInt32() == 0)
{
return;
}
Pen pen = new Pen(Color.Black, 2.0f);
//绘制边框
System.Drawing.Graphics g = Graphics.FromHdc(hDC);
g.DrawLine(pen, 0, this.Height, this.Width, this.Height);
pen.Dispose();
//返回结果
m.Result = IntPtr.Zero;
//释放
ReleaseDC(m.HWnd, hDC);
this.BackColor = SystemColors.Control;
this.BorderStyle = BorderStyle.None;
}
catch { }
}
}
C# WinForm下的只带下边框的TextBox
最新推荐文章于 2024-06-06 21:45:28 发布