Recent

Author Topic: Want to disable ListView scroll bar?  (Read 799 times)

yazigegeda

  • New Member
  • *
  • Posts: 29
Want to disable ListView scroll bar?
« on: May 15, 2024, 01:52:17 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListView1MouseWheelDown(Sender: TObject; Shift: TShiftState;
  2.   MousePos: TPoint; var Handled: Boolean);
  3. begin
  4.   if IsKeyPressed(VK_CONTROL) then
  5.      //How to make the scroll bar of ListView1 not scroll when holding down the Ctrl key.
  6. end;

/How to make the scroll bar of ListView1 not scroll when holding down the Ctrl key  :'(

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Want to disable ListView scroll bar?
« Reply #1 on: May 15, 2024, 02:05:30 pm »
/How to make the scroll bar of ListView1 not scroll when holding down the Ctrl key  :'(
By forbidding execution aslong the key is pressed.
This is how I would do:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   LCLType,
  9.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, Types;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     ListView1: TListView;
  17.     procedure ListView1KeyDown(Sender: TObject; var Key: Word;
  18.       Shift: TShiftState);
  19.     procedure ListView1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
  20.       );
  21.     procedure ListView1MouseWheel(Sender: TObject; Shift: TShiftState;
  22.       WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  23.   private
  24.     FCTRL: Boolean;
  25.   public
  26.  
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36. { TForm1 }
  37.  
  38. procedure TForm1.ListView1KeyDown(Sender: TObject; var Key: Word;
  39.   Shift: TShiftState);
  40. begin
  41.   FCTRL := Key = VK_CONTROL;
  42. end;
  43.  
  44. procedure TForm1.ListView1KeyUp(Sender: TObject; var Key: Word;
  45.   Shift: TShiftState);
  46. begin
  47.   if FCTRL then
  48.     FCTRL := False;
  49. end;
  50.  
  51. procedure TForm1.ListView1MouseWheel(Sender: TObject; Shift: TShiftState;
  52.   WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  53. begin
  54.   if FCTRL then
  55.     Exit;
  56. end;
  57.  
  58. end.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

VisualLab

  • Hero Member
  • *****
  • Posts: 645
Re: Want to disable ListView scroll bar?
« Reply #2 on: May 15, 2024, 02:11:51 pm »
You can also check whether the Shift argument contains the value ssCtrl:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListView1MouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
  2. begin
  3.   if ssCtrl in Shift
  4.     then ListView1.ScrollBars := ssNone
  5.     else ListView1.ScrollBars := ssBoth;
  6. end;

Only... for me, by default, pressing the Ctrl key blocks scrolling (vertical) in the view list (Windows 8.1 64-bit, Lazarus 3.2). So what is this question really about?

 

TinyPortal © 2005-2018