Forum > LCL

Smooth scrolling a TDrawGrid programmatically?

(1/1)

Manlio:
When the smooth scrolling option of a TDrawGrid component is set, we can scroll it down pixel by pixel.

But can we also do that programmatically?

I thought there must be a way, but I could not find it. The scroll bars are not exposed,  ScrollBy doesn't seem to have any effect, and so on - anything I tried didn't work.

Can anyone show me an example of how to scroll up and down by a few pixels?

If possible, something that works on Windows and Mac.

Thank you.

jamie:
Use the "GetScrollInfo" first and from that, make your changes and then use the SetScrollInfo.

These are Windows API's but they should be supported via the LclTinf unit.

You may also need to use the lclType unit

jamie:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, StdCtrls,lcltype,  lclIntf,Lmessages; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    DrawGrid1: TDrawGrid;    procedure Button1Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);Var  S:TScrollinfo;begin  S.fMask :=SIF_Pos;  GetScrollInfo(DrawGrid1.Handle,sb_Vert,S);  inc(S.nPos,1);//<< The amount;  SetScrollInfo(DrawGrid1.Handle,sb_Vert,S,true);  PostMessage(DrawGrid1.Handle, LM_VScroll,sb_ThumbTrack,0); end; end.  

Manlio:
Thank you Jamie, it works perfectly. Very appreciated!

And while I'm here, may I ask another question, also related to TDrawGrid scrolling:

Is it possible to be notified when the user moves the scroll bar?

(And thanks again!)

jamie:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids,Lmessages,lclType,lclintf; type TDrawGrid = Class(Grids.TDrawGrid)   Procedure WMVScroll(Var Msg:TLmessage) Message LM_VScroll; end;   { TForm1 }   TForm1 = class(TForm)    DrawGrid1: TDrawGrid;  private   public   end; var  Form1: TForm1; implementation {$R *.lfm}Procedure TDrawGrid.WMVScroll(Var Msg:TLmessage);Var  S:TScrollInfo; Begin   IF (Msg.lParam =0) Then Begin      S.cbSize := SizeOf(S);      S.fMask :=sif_All;      GetScrollInfo(Handle, SB_Vert, S);      Form1.Caption := S.nPos.Tostring;   end;   inherited; end; end.  
The above code will detect a veritical change via the user or even when posted via software, which leads to the next issue.

If you use a Postmessage..... To send a LM_VSCROLL message, like in the first example, you will need to define the last parameter of the message to something other than 0. This way this current snippet of code can tell the difference, because this event will receive both messages Via user or when you post it.

 I can't say if this is going to work across the targets but that is up to you to try.

Jamie

Navigation

[0] Message Index

Go to full version