Forum > LCL

TScrollingWinControl and scrolling

(1/1)

korba812:
Hello!

I'm trying to port delphi component to lcl. I have got some trouble with TScrollingWinControl descendant. When I scroll this control, scroll bar "Position" property allways point scrolling width (or height) divided by 2.
Next question is about TControlScrollBar. How can I calculate "Page" propery? Should be ClientWidth/Height?

Martin V:
Hi,

I have also problems with ScrollingWinControl. It seems that the Lazarus behaviour is different from Delphi. If you create a sample project with a Form1 and then put a button into the form and then write:


--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
begin
  Height := 500;
  VertScrollbar.Range := 1000;
  VertScrollbar.Position := 250;
end;

--- End code ---
The height of the moveable button should be 50% of the full height of the window and it should be centered, the partitions are 25% above the movable button, 50% moveable button and 25% below the moveable button. In Delphi the behaviour is OK, in Lazarus, the moveable button is only perhaps 10% of the window height instead of 50%.

Is it a bug or is the Lazarus behaviour different?

korba812:
LCL version of TScrollingWinControl is different than VCL and have many inconsistencies.
VCL version dosesn't have Canvas property. is introduced in TCustomControl.
In LCL, when scrollbar position is changed, canvas position is also scrolled. This make many problems eg. popup menu is shown in wrong place. Mouse events coordinates are different than GetCursorPos. etc...

Martin V:
Is there a documentation about LCL tControlScrollbar and tScrollingWinControl ? (besides the 'reference for package lcl')

Martin V:
For porting an existing application, I have decided to write my own Form with Scrollbars based on tScrollbar and not tControlScrollbar. So it is much more close to VCL. I have only added the functionality I needed for my application. Feel free to extend the object. Because I come from WDsibyl and not from Delphi, perhaps there's the need of modifications.


--- Code: ---type
tScrollForm=Class(tForm)
  private
    FScrollBars:TScrollStyle;
    FVertScrollbar, FHorzScrollbar : tScrollbar;
  protected
    procedure OnCreate; override;
    Procedure SetScrollBars(NewValue:TScrollStyle);
    Procedure Scroll(Sender:TObject;ScrollCode:TScrollCode;Var ScrollPos:Longint);virtual;
    property VertScrollbar : tScrollbar read FVertScrollbar; {overwrite the old tControlScrollbar property}
    property HorzScrollbar : tScrollbar read FHorzScrollbar; {overwrite the old tControlScrollbar property}
    Property ScrollBars:TScrollStyle Read FScrollbars Write SetScrollBars;
end;

const
    scColumnLeft = scLineUp;
    scColumnRight = scLineDown;
    scPageLeft = scPageUp;
    scPageRight = scPageDown;
    scHorzPosition = scPosition;
    scVertPosition = scPosition;
    scHorzTrack = scTrack;
    scVertTrack = scTrack;
    scHorzEndScroll = scEndScroll;
    scVertEndScroll = scEndScroll;

implementation

procedure tScrollForm.OnCreate;
  begin
    inherited OnCreate;
    FHorzScrollbar := tScrollbar.Create(self); FHorzScrollbar.Visible := false;
    FHorzScrollbar.Kind := sbHorizontal; FHorzScrollbar.Align := alBottom; FHorzScrollbar.OnScroll := @Scroll;
    InsertControl (FHorzScrollbar);
    FVertScrollbar := tScrollbar.Create(Self); FVertScrollbar.Visible := false;
    FVertScrollbar.Kind := sbVertical; FVertScrollbar.Align := alRight; FVertScrollbar.OnScroll := @Scroll;
    InsertControl (FVertScrollbar);
    fScrollbars := ssNone;
  end;

Procedure tScrollForm.SetScrollBars(NewValue:TScrollStyle);
  begin
    if NewValue = ssBoth then begin
      FVertScrollbar.Visible := true; FHorzScrollbar.Visible := true;
    end
    else if NewValue = ssHorizontal then begin
      FVertScrollbar.Visible := false; FHorzScrollbar.Visible := true;
    end
    else if NewValue = ssVertical then begin
      FVertScrollbar.Visible := true; FHorzScrollbar.Visible := false;
    end
    else begin
      FVertScrollbar.Visible := false; FHorzScrollbar.Visible := false;
    end;
    FScrollbars := NewValue;
  end;

Procedure tScrollForm.Scroll(Sender:TObject;ScrollCode:TScrollCode;Var ScrollPos:Longint);
  begin
  end;

--- End code ---

Navigation

[0] Message Index

Go to full version