gpt4 book ai didi

c# - 中间按钮点击滚动

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:46 25 4
gpt4 key购买 nike

当滚动条可见时,如何在 WinForms 容器控件中实现这一点?

此处突出显示(Google Chrome 浏览器):

enter image description here

编辑:此光标是屏幕截图中唯一可见的光标。我希望我的意思很清楚。

编辑:在我的控制上试过这个。不起作用。

    const int WM_MBUTTONDOWN = 0x207;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_MBUTTONDOWN)
DefWndProc(ref m);
else
base.WndProc(ref m);
}

最佳答案

这是我目前所拥有的。如果我松开中间按钮,它会退出“阅读器模式”,而且我还没有在控件中实现滚动(我使用了文本框),但它可能会给你一些开始的东西。

    [DllImport("comctl32.dll", SetLastError=true,  EntryPoint="#383")]
static extern void DoReaderMode(ref READERMODEINFO prmi);

public delegate bool TranslateDispatchCallbackDelegate(ref MSG lpmsg);
public delegate bool ReaderScrollCallbackDelegate(ref READERMODEINFO prmi, int dx, int dy);

[StructLayout(LayoutKind.Sequential)]
public struct READERMODEINFO
{
public int cbSize;
public IntPtr hwnd;
public int fFlags;
public IntPtr prc;
public ReaderScrollCallbackDelegate pfnScroll;
public TranslateDispatchCallbackDelegate fFlags2;
public IntPtr lParam;
}

[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
public IntPtr hwnd;
public UInt32 message;
public IntPtr wParam;
public IntPtr lParam;
public UInt32 time;
public POINT pt;
}

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
}

[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public int left, top, right, bottom;
}

private bool TranslateDispatchCallback(ref MSG lpMsg)
{
return false;
}
private bool ReaderScrollCallback(ref READERMODEINFO prmi, int dx, int dy)
{
// TODO: Scroll around within your control here

return false;
}

private void EnterReaderMode()
{
READERMODEINFO readerInfo = new READERMODEINFO
{
hwnd = this.textBox1.Handle,
fFlags = 0x00,
prc = IntPtr.Zero,
lParam = IntPtr.Zero,
fFlags2 = new TranslateDispatchCallbackDelegate(this.TranslateDispatchCallback),
pfnScroll = new ReaderScrollCallbackDelegate(this.ReaderScrollCallback)
};
readerInfo.cbSize = Marshal.SizeOf(readerInfo);

DoReaderMode(ref readerInfo);
}

private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Middle)
{
EnterReaderMode();
}
}

关于c# - 中间按钮点击滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13253041/

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