尝试在 RichTextBox 中调整图像大小时光标闪烁 [英] Cursor flickers when trying to resize image in RichTextBox
问题描述
我希望这是一个简单的问题.我执行以下操作:
I hope this is a simple question. I do the following:
- 在 VS2010 中,我创建了一个 Windows 窗体应用程序
- 从工具箱中,将 RichTextBox 控件拖到表单中
- 将表单和 RichTextBox 控件调整为足够大以显示小图片.
- 运行(开始调试).
- 从网络浏览器复制一个小图像并粘贴到富文本框(使用 ctrl-v).
- 在富文本框中选择图像.调整大小的框架显示有小框.
现在,当我将光标放在一个小的缩放框上时,光标会闪烁.我看到了调整大小箭头光标的一瞥,但大多数时候它显示的是工字梁光标.它不会像将图片粘贴到写字板并将光标放在一个调整大小的小框上时那样稳定地显示箭头光标.在 RichTextBox 中调整图片大小是否应该与在 WordPad 中的行为相同?如何停止光标闪烁?
Now when I position the cursor over one of the small resizer boxes, the cursor flickers. I see glimpses of the resize arrow cursor but most the time it displays the I-beam cursor. It does not steadily show the arrow cursors as it does when the a picture is pasted into WordPad and the cursor placed over the one of the small resize boxes. Should resizing a picture in the RichTextBox behave the same as in WordPad? How can I stop the cursor flicker?
推荐答案
通过这个hack,您将能够调整图像大小而不会闪烁,并使用正确的箭头光标
.
With this hack you will be able to resize the image without flickering, and with the correct Arrows Cursors
.
如何
首先,您需要对 RichTextBox
进行子类化并覆盖方法 WndProc
,因此当 RichTextBox
收到消息以更改其 Cursor
,我们将检查图像是否被选中 --- 好吧,我真的不知道是否是 Image
,但它是一个 Object
而不是 Text
.
First you will need to subclass the RichTextBox
and override the method WndProc
, so when the RichTextBox
receives the message to change its Cursor
, we will check if the image is select --- well, I don't really known if is an Image
, but it is an Object
and not Text
.
如果选择了 Image
,我们会将 message
重定向到 DefWndProc
--- 这是默认窗口过程.
If the Image
is selected, we redirect the message
to DefWndProc
--- which is the Default Window Procedure.
代码:
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;
}
}
base.WndProc(ref m);
}
}
这篇关于尝试在 RichTextBox 中调整图像大小时光标闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!