1

There is this question about facebook scrollbars for javascript: hide scrollbar and show on hover like facebook's new chat sidebar and also this question I asked myself with a great answer from a user: How do we make a styled scroll bar for a <div> with mouse wheel sensitive

Anyway, is there a way we can do that kind of scrollbar more stylished and vivible just when we mouse over, just like the facebook's scrollbar, for our delphi programs?

Edit1:

The style problem is something that could be arranged by changing forms styles. Just that fact that we could hide the scroll bars and then show them when the user mouse overs it would already be great!

Community
  • 1
  • 1
NaN
  • 8,596
  • 20
  • 79
  • 153
  • I suggest that you make your own scrollbar with paint/photoshop and you'll use a textbox. – e1che Apr 22 '13 at 06:27

1 Answers1

1

Create a component derived from TListbox and handle the displaying of the scollbar. Example code just as interposed class.

The look can be adapted by designing and own style (with newer Delphi versions).

unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TListBox = Class(StdCtrls.TListBox)
    Constructor Create(AOwner: TComponent); override;
  private
    FHiddenScrollbar: Boolean;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
  published
  public
    Property HiddenScrollbar: Boolean Read FHiddenScrollbar;
  End;

  TForm3 = class(TForm)
    ListBox1: TListBox;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}
{ TListBox }

constructor TListBox.Create;
begin
  inherited;
  FHiddenScrollbar := true;
end;

procedure TListBox.CreateParams(var Params: TCreateParams);
VAR
  Style: Integer;
BEGIN
  inherited;
  if FHiddenScrollbar then
    Params.Style := Params.Style AND not WS_VSCROLL
  else
    Params.Style := Params.Style or WS_VSCROLL;
end;

procedure TListBox.WMMouseMove(var Message: TWMMouseMove);
var
  p: TPoint;
begin
  inherited;
  GetCursorPos(p);
  p := ScreenToClient(p);
  if p.X > (Width - 20) then
  begin
    if FHiddenScrollbar then
    begin
      FHiddenScrollbar := false;
      RecreateWnd;
    end;
  end
  else
  begin
    if not FHiddenScrollbar then
    begin
      FHiddenScrollbar := true;
      RecreateWnd;
    end;
  end;
end;

end.

enter image description here

bummi
  • 27,123
  • 14
  • 62
  • 101
  • @RobKennedy where is my mistake? The idea was handling(hide/display) scrollbars by code and using self defined styles for a "fresh" look. http://theroadtodelphi.wordpress.com/2011/09/01/exploring-delphi-xe2-vcl-styles-part-i/ – bummi Apr 22 '13 at 14:19
  • I think I finally understand your answer. Your mistake is assuming readers will know exactly what you're talking about. – Rob Kennedy Apr 22 '13 at 14:39
  • Just the fact that we could hide and them show scroll bars at mouse over would help very much because we could use form styles to change all controls appearance. – NaN Apr 24 '13 at 13:34
  • @EASI you are using could and would, does shown code not work for you? – bummi Apr 24 '13 at 13:55
  • I am sorry, but the code did not had any effect on the scrollbars of the component. :-( – NaN May 09 '13 at 19:22
  • My code was on usual TListBox = Class(StdCtrls.TListBox), if you are using a derived you will have to adapt it, or better integrate it into your component. – bummi May 09 '13 at 19:38