解决方案 »
- 当panel的AutoScroll=true 时,Location不准
- 如何让一个WEB页面24小时一直开启,不过期??
- 给已经绑定了数据的datagridview中在添加一列数据
- 高分求代码!
- 引用的问题
- (菜鸟提问)about Textbox
- 那位前辈能给我能下载VS2005或2008的网站啊 我找了好久都没有一个能下的 谢谢~!!!
- 如何上传大文件
- winfrom如何将一个按钮控件的图片,用在另一个控件上。按钮的image属性是System.Drawing.Bitmap
- 如何打开CHM文件中指定的页面
- 如何获得存储过程中select的值
- Datagridview的一个简单问题,先到先得分
.inputT {
BORDER-RIGHT: #412e2f 0px solid;
BORDER-TOP: #412e2f 0px solid;
BACKGROUND: #fff;
BORDER-LEFT: #412e2f 0px solid;
BORDER-BOTTOM: #412e2f 1px solid;
width:120px;
}
这是我样式表里面的,你自己改改
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;public class MyTextBox : System.Windows.Forms.TextBox
{
#region 常量 const int WM_NCPAINT = 0x85;
const int WM_PAINT = 0xf;
const int MY_NCPAINT = 0xff; #endregion #region WindowsAPI [DllImport("User32")]
static extern int SendMessage(
IntPtr hWnd,
uint Msg,
uint wParam,
uint lParam
);
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); #endregion #region 变量 Color _BorderColor = Color.Black;
Color _FocusedColor = Color.FromArgb(100, 100, 230);
bool _FocusIn = false; #endregion #region 重载方法
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if ((m.Msg == WM_NCPAINT || m.Msg == WM_PAINT))
{
PaintBorder(m);
m.Result = IntPtr.Zero;
}
} protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
_FocusIn = true;
SendMessage(this.Handle, WM_NCPAINT, 0, MY_NCPAINT);
} protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
_FocusIn = false;
SendMessage(Handle, WM_NCPAINT, 0, MY_NCPAINT);
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
SendMessage(this.Handle, WM_NCPAINT, 0, MY_NCPAINT);
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
SendMessage(this.Handle, WM_NCPAINT, 0, MY_NCPAINT);
} #endregion #region 画边框
private void PaintBorder(Message m)
{
IntPtr hdc = GetWindowDC(m.HWnd);
if (hdc.ToInt32() == 0)
return;
Graphics g = Graphics.FromHdc(hdc); Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
Point point = rect.Location;
point.Offset(2, 2);
Size size = rect.Size;
size.Width -= 4;
size.Height -= 4; Rectangle rclient = new Rectangle(point, size); Pen p = null;
Region region = new Region(rect);
region.Exclude(rclient);
if ((_FocusIn || Focused) && m.LParam.ToInt32() == MY_NCPAINT)
{
p = new Pen(new SolidBrush(_FocusedColor), 2);
g.SetClip(region, System.Drawing.Drawing2D.CombineMode.Intersect);
g.FillRegion(new SolidBrush(this.BackColor), region);
g.DrawRectangle(p, new Rectangle(new Point(0, 0), new Size(rect.Width, rect.Height)));
}
else
{
p = new Pen(new SolidBrush(_BorderColor), 1);
if (m.LParam.ToInt32() == MY_NCPAINT)
g.SetClip(region, System.Drawing.Drawing2D.CombineMode.Intersect);
g.FillRegion(new SolidBrush(this.BackColor), region);
g.DrawLine(p, new Point(rect.Left, rect.Bottom - 1), new Point(rect.Right, rect.Bottom - 1));
}
ReleaseDC(m.HWnd, hdc);
}
#endregion
}