覆盖一些.NET Framework的绘图控制来改变它的边框颜色? [英] Override the drawing of some .Net Framework controls to change its border color?
问题描述
情景
我使用的是第三方窗口的视觉主题。
I'm using a 3rd party windows visual theme.
当我看到我的应用程序,它看起来是这样的:
When I see my application, it looks like this:
但是,当我用的是普通的航空主题,它看起来与可怕的白色边框无处不在:
But when I use the normal Aero theme, it looks with horrible white borders everywhere:
问题
我知道,在应用程序中使用的颜色方案依赖于视觉风格,但是:
I know that the color-scheme used in the app depends on the visual style, but:
我可以继承文本框
,组合框
和的TabControl
修改绘制边框颜色采用较深的颜色?如何?
I can inherit the TextBox
, ComboBox
, and TabControl
to change the drawn border color to use a darker color? How to?
更新
我的文本框使用 Fixed3D
我的组合框使用了的FlatStyle
财产扁平
的值,并设置为 DropDownList的
My ComboBoxes are using a FlatStyle
property with value of Flat
, and are set as DropDownList
推荐答案
您可以赶上 WM_PAINT
或 WM_ERASEBKGND
消息并手动绘制边框:
You can catch the WM_PAINT
or WM_ERASEBKGND
message and draw the border manually:
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC);
protected override void WndProc(ref Message m)
{
IntPtr hdc;
if (m.Msg == 0x14) //WM_ERASEBKGND
{
hdc = GetWindowDC(m.HWnd);
if (hdc != IntPtr.Zero)
{
using (Graphics g = Graphics.FromHdc(hdc))
{
g.DrawRectangle(Pens.Red, 0, 0, this.Width-1, this.Height-1);
}
ReleaseDC(m.HWnd, hdc);
}
base.WndProc(ref m);
}
但它确实有一个问题,当文本框失去它的焦点。
It does have however a problem when the textbox looses it's focus.
这篇关于覆盖一些.NET Framework的绘图控制来改变它的边框颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!