设置编辑控件中的滚动位置

发布于 2024-10-12 13:46:18 字数 63 浏览 3 评论 0原文

我正在尝试在编辑控件中设置滚动位置,并且希望将其设置为从顶部到底部的 20%。我怎样才能通过百分比来做到这一点?

I'm trying to set the scroll position in edit control and I want set it 20% to bottom from the top. how I may go do that by taking a percentage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忱杏 2024-10-19 13:46:18

当窗口的标准垂直滚动条中发生滚动事件时,WM_VSCROLL 消息将发送到窗口。当垂直滚动条控件中发生滚动事件时,该消息也会发送给该控件的所有者。

http://msdn.microsoft.com/en -us/library/bb787577%28v=vs.85%29.aspx

您可以先 GetScrollRange() (http://msdn.microsoft.com/en-us/library/ bb787587%28v=vs.85%29.aspx),计算有多少行,然后计算百分比。之后 WindowProc()VM_SCROLL 或者更简单的解决方案使用 SetScrollPos() 函数 http://msdn.microsoft.com/en-us/library/bb787597%28v= vs.85%29.aspx

您可以在此处找到所有滚动功能http://msdn.microsoft.com/en-us/library/ff486021%28v=VS.85%29.aspx

希望这会有所帮助。

The WM_VSCROLL message is sent to a window when a scroll event occurs in the window's standard vertical scroll bar. This message is also sent to the owner of a vertical scroll bar control when a scroll event occurs in the control.

http://msdn.microsoft.com/en-us/library/bb787577%28v=vs.85%29.aspx

You can first GetScrollRange() (http://msdn.microsoft.com/en-us/library/bb787587%28v=vs.85%29.aspx), calculate how many lines there are, then calculate the percentage. Afterward WindowProc() with VM_SCROLL or, of a much more simpler solution use the SetScrollPos() function http://msdn.microsoft.com/en-us/library/bb787597%28v=vs.85%29.aspx

You can find all the scroll functions here http://msdn.microsoft.com/en-us/library/ff486021%28v=VS.85%29.aspx

Hope this helped.

冰雪梦之恋 2024-10-19 13:46:18

特别是对于编辑控件设置,滚动位置似乎并未实际将文本移动到预期位置。滚动条位置发生移动,但文本保持在原来的位置。

要滚动编辑框,我发现以下内容可以按我的预期工作:

double desiredPercentage = 0.7;
CEdit* pEditBox = (CEdit*)GetDlgItem(IDC_CONTROLID)

int totalLines = pEditLog->GetLineCount();
// Truncatest to the nearest int, do different rounding method for round up/down.
int scrollLine = (int)(desiredPercentage * (double)totalLines));

pEditBox->LineScroll(scrollLine);

Specifically for an edit control setting the scroll position doesn't appear to actually move the text to the position expected. The scroll bar position is moved but the text stays where it is at.

To scroll an edit box I found the following to work as I expected:

double desiredPercentage = 0.7;
CEdit* pEditBox = (CEdit*)GetDlgItem(IDC_CONTROLID)

int totalLines = pEditLog->GetLineCount();
// Truncatest to the nearest int, do different rounding method for round up/down.
int scrollLine = (int)(desiredPercentage * (double)totalLines));

pEditBox->LineScroll(scrollLine);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文