在C#RichTextBox中设置水平滚动条以进行32位滚动 [英] Set horizontal scrollbar for 32 bit scrolling in a C# RichTextBox

查看:199
本文介绍了在C#RichTextBox中设置水平滚动条以进行32位滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于在此之前的帖子,我已经成功控制了RichTextBox中的垂直滚动条: https://stackoverflow.com/a/5611856/848344 .但是如何控制水平滚动条?

I have successfully controlled the vertical scrollbar in a RichTextBox thanks to the earlier post here: https://stackoverflow.com/a/5611856/848344. But how do I control the horizontal scrollbar?

该方法已填入setVerticalScroll().我只需要在setHorizo​​ntalScroll()中填写,上面写着在这里插入小企鹅".

The method is filled in for setVerticalScroll(). I just need it filled in for setHorizontalScroll() where it says "Insert gubbins here.".

// 32 bit scrolling of pane slider
// https://stackoverflow.com/questions/1380104/cc-setscrollpos-user32-dll
[DllImport("user32.dll")]
static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw);
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("User32.dll")]
private extern static int GetScrollPos(IntPtr hWnd, int nBar);
private enum ScrollBarType : uint { SbHorz = 0, SbVert = 1, SbCtl = 2, SbBoth = 3 }

public void setVerticalScroll(IntPtr hWnd, int pos) {
    SetScrollPos(hWnd, 0x1, pos, true);
    PostMessage(hWnd, 0x115, 4 + 0x10000 * pos, 0);
}
public void setHorizontalScroll(IntPtr hWnd, int pos) {
    /////////////////////////////////////
    //////////////// Insert gubbins here.
    /////////////////////////////////////
}
public int getVerticalScroll(IntPtr hWnd) {
    int n = GetScrollPos(hWnd, (int)ScrollBarType.SbVert);
    return n;
}
public int getHorizontalScroll(IntPtr hWnd) {
    int n = GetScrollPos(hWnd, (int)ScrollBarType.SbHorz);
    return n;
}

推荐答案

通过反复尝试和运气,我想我找到了解决方案.我只是从0x115值减去1,得到0x114(并将0x1更改为0x0):

Through trial and error along with sheer luck, I think I found the solution. I just minus one from the 0x115 value to make 0x114 (and also changed 0x1 to 0x0):

public void setHorizontalScroll(IntPtr hWnd, int pos)
{
    SetScrollPos(hWnd, 0x0, pos, true);
    PostMessage(hWnd, 0x114, 4 + 0x10000 * pos, 0);
}

如果有人可以检查一下,我将不胜感激.

If someone could check that though, I'd be grateful.

这篇关于在C#RichTextBox中设置水平滚动条以进行32位滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆