richtextbox自动滚动的问题

pccc1984 2010-10-17 08:20:20
自动滚动已经搞定。但现在的问题是,加载的文档越长,滚动越快。怎么让它无论加载的文档多长。都保持给定的速度。

private int min, max;
private int pos = 0;
private int endPos = 0;
private const int SB_HORZ = 0x0;
private const int SB_VERT = 0x1;
private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;
private const int SB_THUMBPOSITION = 4;
[DllImport("user32.dll")]
private static extern int SetScrollPos(IntPtr hwnd, int nBar, int nPos, bool bRedraw);

[DllImport("user32.dll")]
private static extern int GetScrollPos(IntPtr hwnd, int nBar);
[DllImport("user32.dll")]
private static extern bool PostMessage(IntPtr hWnd, int nBar, int wParam, int lParam);
[DllImport("user32", CharSet = CharSet.Auto)]
private static extern bool GetScrollRange(IntPtr hWnd, int nBar, out int lpMinPos, out int lpMaxPos);
private void rt_DoubleClick(object sender, EventArgs e)
{
timeAutoScroll.Interval = 100;
timeAutoScroll.Interval -= t.AutoScrollSpeed;
//得到滚动条的最大最小值
GetScrollRange(rt.Handle, SB_VERT, out min, out max);
//得到滚动条到最底下的实际位置
endPos = max - rt.ClientRectangle.Height;
this.timeAutoScroll.Enabled = true;

}

private void timeAutoScroll_Tick(object sender, EventArgs e)
{
pos = GetScrollPos(rt.Handle, SB_VERT);//加上这句是为了如果用户手动拖拽滚动条,可以保证滚动条继续从拖拽的位置走
pos++;
//如果已经到底,那么停止Timer
if (pos > endPos)
{
this.timeAutoScroll.Enabled = false;
return;
}
SetScrollPos(rt.Handle, SB_VERT, pos, true);
PostMessage(rt.Handle, WM_VSCROLL, SB_THUMBPOSITION + 0x10000 * pos, 0);
//PostMessage(rt.Handle, WM_VSCROLL, SB_THUMBPOSITION + pos*100000, 0);
}
...全文
464 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
J-Sunny 2012-05-09
  • 打赏
  • 举报
回复
我也用拷贝的这段代码 ,但是我的不知道怎么用啊 滚动不了
xiaowaigg 2012-04-25
  • 打赏
  • 举报
回复
timeAutoScroll.Interval -= t.AutoScrollSpeed; 中 t是什么控件或者变量 怎么会有.AutoScrollSpeed ,你用的是vs哪个版本
feile922 2010-10-21
  • 打赏
  • 举报
回复
没有高人指点一下啊
pccc1984 2010-10-18
  • 打赏
  • 举报
回复
有没有高人指点一下啊
pccc1984 2010-10-17
  • 打赏
  • 举报
回复

[Quote=引用 1 楼 wuyq11 的回复:]
protected override void WndProc(ref Message m)
{
int n = 20;//该值越大,滑轮滚动速度超快

case WM_MOUSEWHEEL:
中滚动,控制pos-=n;

}
[/Quote]

没看懂。。
wuyq11 2010-10-17
  • 打赏
  • 举报
回复
protected override void WndProc(ref Message m)
{
int n = 20;//该值越大,滑轮滚动速度超快

case WM_MOUSEWHEEL:
中滚动,控制pos-=n;

}

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧