0
votes

I'm using Delphi XE5 with a Style applied.

When using a DBGrid that has enough records to show the vertical scroll bar, clicking and dragging the scroll bar results in a choppy animation. The grid keeps repainting/updating.

If I set the DBGRID.StyleElement.seBorder to False, it behaves normally, e.g. you can drag the scroll bar to the top or to the bottom without it changing/repainting the grid until you unpress the mouse button.

Is there any way to make the vertical scroll bar behave when the Styles is on?

1

1 Answers

0
votes

This is what i have done to make a Styled Grid behave like the non styled grid when scrolling.

unit xStyleFixes;

interface
uses forms, Vcl.Buttons, Vcl.StdCtrls, Windows, Messages, SysUtils, Classes, Graphics, Controls, themes, Wwdbgrid, typinfo, DBGrids;

type
  TFixScrollingStyleHook = class (TScrollingStyleHook)
    var ScrollBarthumbBtnWasPressed : Boolean;
    procedure WMVScroll(var Msg: TMessage); message WM_VSCROLL;
 end;

implementation

procedure TFixScrollingStyleHook.WMVScroll(var Msg: TMessage); 
var sTest : String;
begin
  if VertSliderState = tsThumbBtnVertPressed then begin
    ScrollBarthumbBtnWasPressed := true;
    Handled := True;
  end else begin
    if ScrollBarthumbBtnWasPressed then begin
      if Self.VertTrackRect.TopLeft = self.VertSliderRect.TopLeft then
        TWMVScroll(Msg).ScrollCode := SB_TOP;
      if Self.VertTrackRect.BottomRight = self.VertSliderRect.BottomRight then
        TWMVScroll(Msg).ScrollCode := SB_BOTTOM;
      ScrollBarthumbBtnWasPressed := False;
    end;
    CallDefaultProc(TMessage(Msg));
    PaintScroll;
  end;
end;

initialization
  TCustomStyleEngine.RegisterStyleHook(TWWDbGrid, TFixScrollingStyleHook );
  TCustomStyleEngine.RegisterStyleHook(TDbGrid, TFixScrollingStyleHook );
end.

This is my first time playing with Style hooks so if you can see a better way to do this please let me know