Delphi 滚动条的使用介绍
<p><span style="font-size: 16px">Delphi 滚动条的使用介绍</span></p><p><strong><span style="font-size: 16px">1、DELPHI的滚动条默认发送消息格式:</span></strong></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">function TControl.Perform(
Msg: Cardinal;
WParam: WPARAM;
LParam: LPARAM
): LRESULT;
//如:Memo1.Perform(WM_HSCROLL, SB_LEFT, 0);</span></pre>
</div>
<p> </p>
<p><span style="font-size: 16px"><strong>2、水平/垂直滚动条:</strong></span></p>
<p><span style="font-size: 16px"><strong>2.1 水平滚动条</strong> 消息 WM_HSCROLL </span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;">SendMessage(Memo1.Handle, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, 50), 0); //滚动至此
SendMessage(Memo1.Handle, WM_HSCROLL, SB_LEFT, 0); //左边缘
SendMessage(Memo1.Handle, WM_HSCROLL, SB_RIGHT, 0); //右边缘
SendMessage(Memo1.Handle, WM_HSCROLL, SB_PAGELEFT, 0); //向左翻页
SendMessage(Memo1.Handle, WM_HSCROLL, SB_PAGERIGHT, 0); //向右翻页
SendMessage(Memo1.Handle, WM_HSCROLL, SB_LINELEFT, 0); //向左滚动
SendMessage(Memo1.Handle, WM_HSCROLL, SB_LINERIGHT, 0); //向右滚动
</pre>
</div>
<p> </p>
<p><span style="font-size: 16px"><strong>2.2 垂直滚动条</strong> 消息 WM_VSCROLL </span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;">SendMessage(Memo1.Handle, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, 50), 0); //滚动至此 50为位置 滚动到指定行号
SendMessage(Memo1.Handle, WM_VSCROLL, SB_TOP, 0); //顶部
SendMessage(Memo1.Handle, WM_VSCROLL, SB_BOTTOM, 0); //底部
SendMessage(Memo1.Handle, WM_VSCROLL, SB_PAGEUP, 0); //向上翻页
SendMessage(Memo1.Handle, WM_VSCROLL, SB_PAGEDOWN, 0); //向下翻页
SendMessage(Memo1.Handle, WM_VSCROLL, SB_LINEUP, 0); //向上滚动
SendMessage(Memo1.Handle, WM_VSCROLL, SB_LINEDOWN, 0); //向下滚动
</pre>
</div>
<p> </p>
<p><strong><span style="font-size: 16px">3、获得滚动条的位置(GetScrollPos函数)</span></strong></p>
<p><span style="font-size: 16px">GetScrollPos函数检索指定滚动条中滚动框(拇指)的当前位置。当前位置是一个相对值,取决于当前滚动范围。</span><br><span style="font-size: 16px">例如,如果滚动范围为0到100,并且滚动框位于条的中间,则当前位置为50。</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">int GetScrollPos(
HWND hWnd,
int nBar
);
</span></pre>
</div>
<p><span style="font-size: 16px">示例:</span></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">var
h, v: Integer;
begin
h := GetScrollPos(Memo1.Handle, SB_HORZ);
v := GetScrollPos(Memo1.Handle, SB_VERT);
Caption := Format('水平数值=%d 垂直数值=%d', );
end;
</span></pre>
</div>
<p><span style="font-size: 16px"> </span></p>
<p><strong><span style="font-size: 16px">4、显示和隐藏滚动条</span></strong></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">ShowScrollBar(Memo1.Handle,SB_HORZ,false); //隐藏MEMO水平滚动条
ShowScrollBar(Memo1.Handle,SB_VERT,false); //隐藏MEMO垂直滚动条
</span></pre>
</div>
<p><span style="font-size: 16px"> </span></p>
<p><strong><span style="font-size: 16px">5、判断 滚动条是否出现</span></strong></p>
<div class="cnblogs_Highlighter">
<pre class="brush:delphi;gutter:true;"><span style="font-size: 16px">procedure TForm1.Button1Click(Sender: TObject);
begin
if (GetWindowlong(Memo1.Handle, GWL_STYLE) and WS_VSCROLL) > 0 then ShowMessage('垂直滚动条显示');
if (GetWindowlong(Memo1.Handle, GWL_STYLE) and WS_HSCROLL) > 0 then ShowMessage('水平滚动条显示');
end;
</span></pre>
</div>
<p><span style="font-size: 16px"> </span></p>
<p><span style="font-size: 14px; color: rgba(136, 136, 136, 1)">创建时间:2019.11.18 更新时间:2020.05.18</span></p>
<p><span style="font-size: 16px"> </span></p>
</div>
<div id="MySignature" role="contentinfo">
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!<br><br>
来源:https://www.cnblogs.com/guorongtao/p/11880391.html
頁:
[1]