zoukankan      html  css  js  c++  java
  • 使Form响应滚轮事件

    这里只举个纵轴的例子,利用Delphi的VCL控件的原有代码还是比较方便的,代码如下:

    MouseWheel
    procedure TfrmMain.FormMouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; 
    var Handled: Boolean);
    var
      Lpos,LHeight :integer;
    begin
      
    //确保FORM的 AutoScroll := False; Scaled := True;
      
    //要在窗体建立或者内容载入的时候设置好 VertScrollBar.Range visible
      
    //根据实际的内容长度来设置VertScrollBar.Range
      LHeight :
    = VertScrollBar.Range - ClientHeight;
      
    //注意form的 ClientHeight和Height的区别
      
    if LHeight <= 0 then Exit;
      IF WheelDelta 
    > 0 THEN
        Lpos :
    = VertScrollBar.Position - VertScrollBar.Increment
      ELSE
        Lpos :
    = VertScrollBar.Position + VertScrollBar.Increment;
      
    if  Lpos > LHeight then
         Lpos :
    = LHeight  ;
      
    if  Lpos < 0  then
         Lpos :
    = 0;
      
    if VertScrollBar.Position -Lpos  <> 0 then
      
    begin
        
    //ScrollBy(0,self.VertScrollBar.Position-lpos);
        
    //由于设置POSITION的时候已经使form滚动了,所以不用手动滚动
        VertScrollBar.Position :
    = Lpos;
      
    end;
      Handled :
    = true; //屏蔽form里面的控件滚动事件
    end;

    当然也可以自己截取MouseWheel消息,这样就不单单只有TScrollingWinControl类上使用滚轮事件了

  • 相关阅读:
    软件测试流程
    Python2 RF(3.0.4)与Python3 RF(3.1.2)区别
    Ubuntu Install RobotFramework with Python3
    Beta测试与Alpha测试有什么区别
    网络协议,如TCP/UDP的区别?
    缺陷相关知识
    linux_machine-id
    monkey自定义脚本实践
    Monkey事件
    Linux虚拟机fdisk分区
  • 原文地址:https://www.cnblogs.com/enli/p/1757606.html
Copyright © 2011-2022 走看看