有关于javascript的facebook滚动条的问题:hide scrollbar and show on hover like facebook's new chat sidebar此问题我问自己一个用户的好答案:How do we make a styled scroll bar for a <div> with mouse wheel sensitive
无论如何,有没有一种方法可以让我们在我们的delphi程序中鼠标悬停时更加风格化和活泼,就像facebook的滚动条一样?
样式问题可以通过改变表单样式来安排。只是这个事实,我们可以隐藏滚动条,然后当用户鼠标悬停它时显示它们已经很棒了!
答案 0 :(得分:1)
创建从TListbox派生的组件并处理scollbar的显示。 示例代码就像插入的类一样。
可以通过设计和自己的风格(使用较新的Delphi版本)来调整外观。
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.