我正在尝试处理DWM Glass下的TextBox文本的颜色.
我读了很多材料,还没有完美的解决方案.
我读了很多材料,还没有完美的解决方案.
几乎完美的结果代码我发现这里:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/316a178e-252b-480d-8cc9-85814c2073d8/,但它有很多轻弹和事件特定的操作(例如:键入一些文本,并按下主页按钮).
我试图解决这些问题.
以下代码是原始代码的突变,但它不依赖于任何事件,只是WM_PAINT.它仍然闪烁,插入符号(文本光标)以某种方式消失!
谢谢.
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Drawing.Imaging; using System.Diagnostics; namespace AeroWindowsFormsApplication { public class AeroTextBox : TextBox { private const int WM_PAINT = 0xf; private bool _aeroFix; public AeroTextBox() { SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint,true); } protected override void WndProc(ref Message m) { if (_aeroFix) { switch (m.Msg) { case WM_PAINT: RedrawAsBitmap(); m.Result = new IntPtr(1); break; default: base.WndProc(ref m); break; } } else { base.WndProc(ref m); } } private void RedrawAsBitmap() { using (Bitmap bm = new Bitmap(this.Width,this.Height)) using (Graphics g = this.CreateGraphics()) { this.DrawToBitmap(bm,this.ClientRectangle); g.DrawImageUnscaled(bm,-1,-1); } } public bool AeroFix { get { return _aeroFix; } set { if (_aeroFix != value) { Invalidate(); } _aeroFix = value; } } } }