|
|
傻傻的香烟 · python deepcopy ...· 1 年前 · |
|
|
骑白马的红茶 · 我用 JavaScript ...· 2 年前 · |
|
|
考研的松树 · c++ - 避免在 Google Mock ...· 2 年前 · |
|
|
会开车的熊猫 · Springboot ...· 2 年前 · |
我希望这是一个简单的问题。我所做的工作如下:
现在,当我将光标定位在一个小的大小框上时,光标会闪烁。我看到了调整箭头光标大小的一瞥,但大多数时候它会显示I波束光标。它不会稳定地显示箭头游标,就像将图片粘贴到WordPad并将光标放置在一个小的调整大小框上时一样。在RichTextBox中调整图片大小是否与在WordPad中的行为相同?如何阻止光标闪烁?
使用下列属性
/// <summary>
/// The Lower property CreateParams is being used to reduce flicker
/// </summary>
protected override CreateParams CreateParams
const int WS_EX_COMPOSITED = 0x02000000;
var cp = base.CreateParams;
cp.ExStyle |= WS_EX_COMPOSITED;
return cp;
}
我已经回答了 here 。
2018年这个问题还在发生..。
这不是最好的,但我创造了一个解决办法。我相信我们可以改进这个代码--也许在将来我会自己做。
您需要子类
RichTextBox
,然后添加以下内容,以强制
Cursor
达到应有的效果。
注意,对于像图片这样的对象,
Cursor
要么是
Cross
,要么对于文本是
I-Beam
。
它的工作原理:
RichTextBox
请求更改游标(
SetCursor
)时,我们都会拦截它并检查对象是否为
Selected
。
Cross
的游标。如果为false,则将其更改为
I-Beam
。
class RichTextBoxEx : RichTextBox
private const int WM_SETCURSOR = 0x20;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SetCursor(IntPtr hCursor);
protected override void WndProc(ref Message m) {
if (m.Msg == WM_SETCURSOR)
if (SelectionType == RichTextBoxSelectionTypes.Object)
// Necessary to avoid recursive calls
if (Cursor != Cursors.Cross)
Cursor = Cursors.Cross;
// Necessary to avoid recursive calls
if (Cursor != Cursors.IBeam)
Cursor = Cursors.IBeam;
SetCursor(Cursor.Handle);
return;
base.WndProc(ref m);
}
使用此
hack
,您将能够在不闪烁的情况下调整图像的大小,并使用正确的
Arrows Cursors
。
How
首先,您需要子类
RichTextBox
并覆盖方法
WndProc
,所以当
RichTextBox
接收到消息以更改其
Cursor
时,我们将检查图像是否被选中--我不知道它是否是
Image
,但它是
Object
而不是
Text
。
如果选择了
Image
,我们将
message
重定向到
DefWndProc
--这是默认的窗口过程。
代码:
public class RichTextBoxEx : RichTextBox
private const int WM_SETCURSOR = 0x20;
protected override void WndProc(ref Message m)
if (m.Msg == WM_SETCURSOR)
if (SelectionType == RichTextBoxSelectionTypes.Object)
DefWndProc(ref m);
return;