zoukankan      html  css  js  c++  java
  • Delphi 滚动条的使用介绍

    Delphi 滚动条的使用介绍

    1、DELPHI的滚动条默认发送消息格式:

    function TControl.Perform(
      Msg: Cardinal;
      WParam: WPARAM;
      LParam: LPARAM
    ): LRESULT;
    //如:Memo1.Perform(WM_HSCROLL, SB_LEFT, 0);

    2、水平/垂直滚动条:

    2.1 水平滚动条 消息 WM_HSCROLL

    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); //向右滚动
    

      

    2.2 垂直滚动条 消息 WM_VSCROLL

    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); //向下滚动
    

      

    3、获得滚动条的位置(GetScrollPos函数)

    GetScrollPos函数检索指定滚动条中滚动框(拇指)的当前位置。当前位置是一个相对值,取决于当前滚动范围。
    例如,如果滚动范围为0到100,并且滚动框位于条的中间,则当前位置为50。

    int GetScrollPos( 
      HWND hWnd,
      int nBar
    );
    

    示例:

    var
      h, v: Integer;
    begin
      h := GetScrollPos(Memo1.Handle, SB_HORZ);
      v := GetScrollPos(Memo1.Handle, SB_VERT);
      Caption := Format('水平数值=%d 垂直数值=%d', [h, v]);
    end;
    

      

    4、显示和隐藏滚动条

    ShowScrollBar(Memo1.Handle,SB_HORZ,false); //隐藏MEMO水平滚动条
    ShowScrollBar(Memo1.Handle,SB_VERT,false); //隐藏MEMO垂直滚动条
    

      

    5、判断 滚动条是否出现

    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;
    

      

    创建时间:2019.11.18  更新时间:2020.05.18

     

  • 相关阅读:
    使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration
    Mysql Lost connection to MySQL server at ‘reading initial communication packet', system error: 0
    mysql-基本命令
    C# 监听值的变化
    DataGrid样式
    C# 获取当前日期时间
    C# 中生成随机数
    递归和迭代
    PHP 时间转几分几秒
    PHP 根据整数ID,生成唯一字符串
  • 原文地址:https://www.cnblogs.com/guorongtao/p/11880391.html
Copyright © 2011-2022 走看看