c# – 在DWM玻璃下使用TextBox进行测试
发布时间:2020-12-15 17:45:42 所属栏目:百科 来源:网络整理
导读:我正在尝试处理DWM Glass下的TextBox文本的颜色. 我读了很多材料,还没有完美的解决方案. 几乎完美的结果代码我发现这里:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/316a178e-252b-480d-8cc9-85814c2073d8/,但它有很多轻弹和事件特定
我正在尝试处理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; } } } } 解决方法
如果将窗体中的TransparencyKey设置为玻璃区域中的背景颜色,则可以对其使用任何控件,但不能使用放置在其中的任何一个控件中的TransparencyKey中指定的颜色.
这种方法不方便您在后台点击窗口上的玻璃.但也可能有一种方法. 编辑:我一直在寻找这个很长一段时间,这一定是不可能的. Carret由Windows API本身管理,您不能强制它以您想要的方式显示.你可以做的是自己绘制整个文本框,但是这么多工作太少了. 我的总结:GDI和DWM并没有很好的结合.我放弃. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |