簡體   English   中英

在C#RichTextBox中設置水平滾動條以進行32位滾動

[英]Set horizontal scrollbar for 32 bit scrolling in a C# RichTextBox

多虧了之前的帖子,我已經成功控制了RichTextBox中的垂直滾動條: https : //stackoverflow.com/a/5611856/848344 但是,如何控制水平滾動條?

將為setVerticalScroll()填充該方法。 我只需要在setHorizo​​ntalScroll()中填寫“在這里插入小企鵝”。

// 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):

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

如果有人可以檢查一下,我將不勝感激。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM