gpt4 book ai didi

C# WinForms RichTextBox 鼠标中键滚动 : prevent the arrow cursor

转载 作者:太空宇宙 更新时间:2023-11-03 14:53:37 24 4
gpt4 key购买 nike

在 C# WinForms 中,我有一个自定义的 RichTextBox,我自己在其中处理鼠标中键的滚动。完成后,我想显示我自己的光标。当按下中间按钮时,我在 MouseDown 事件中切换到此光标。

    void richText_MouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Middle) {
Cursor.Current = MainForm.cursors["hand_NS"];
}
}

但是,文本框会立即切换到 Windows“箭头”光标。这似乎是 RichTextBox autom 的一部分。行为,在 MouseDown 或 MouseMove 中。我可以通过在 MouseMove 中不断显示我的光标来覆盖它,但它看起来很闪烁,因为两个光标互相争斗。我能以某种方式阻止自动切换到“箭头”光标吗?

编辑:尝试设置 Cursor 属性:

 void richText_MouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Middle) {
richText.Cursor = MainForm.cursors["hand_NS"];
//Cursor.Current = MainForm.cursors["hand_NS"];
}
}

恢复 I 型光标:

void richText_MouseUp(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Middle) {
richText.Cursor = Cursors.IBeam;
//Cursor.Current = Cursors.IBeam;
}

最佳答案

通过向它 throw 我能找到的所有火炮,终于让它正常工作(几乎没有闪烁)。在 MouseMove 中完成的操作(如下)也在 MouseDown 中完成。

    public const uint LVM_SETHOTCURSOR = 4158;
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);


void richText_MouseMove(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Middle) {
this.TopLevelControl.Cursor = Cursors.PanNorth;
richText.Cursor = Cursors.PanNorth;
SendMessage(richText.Handle, LVM_SETHOTCURSOR, IntPtr.Zero, Cursors.PanNorth.Handle);
Cursor.Current = Cursors.PanNorth;
}
}

覆盖 RTB 控件中的 SETCURSOR 消息:

    [DllImport("user32.dll")]
public static extern int SetCursor(IntPtr cursor);
private const int WM_SETCURSOR = 0x20;

protected override void WndProc(ref System.Windows.Forms.Message m) {
if (m.Msg == WM_SETCURSOR) {
SetCursor(Cursors.PanNorth.Handle);
m.Result = new IntPtr(1);
return;
}
base.WndProc(ref m);
}

来源:

ListView Cursor changing & flickering

Mouse cursor flickers over selected text - how to prevent this?

关于C# WinForms RichTextBox 鼠标中键滚动 : prevent the arrow cursor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50654990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com