2

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

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

在此处输入图像描述

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

编辑:在我的控制下尝试了这个。不工作。

    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);
    }
4

2 回答 2

2

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

    [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();
        }
    }
于 2012-11-06T15:55:14.193 回答
0

默认情况下,当您按下鼠标滚轮按钮时,RichTextBox 控件会执行此操作。

编辑:对不起,我误解了,并认为您是在询问在文本框中而不是容器控件中执行此操作

于 2012-11-06T14:33:08.413 回答