I have a graphical TCustomControl
descendant component with a system scrollbar on it. The problem is that when I move the window half outside the screen and then I drag it back, the scrollbar disappers (it's not painted). How can I fix this ? I'm thinking, maybe I should call the scrollbar Paint
method in component Paint
but I don't know how.
Here is the code. There is no need install the component or to put something on the main form, just copy the code and assign TForm1.FormCreate
event:
Unit1.pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SuperList;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
List: TSuperList;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
List:=TSuperList.Create(self);
List.AlignWithMargins:=true;
List.Align:=alClient;
List.Visible:=true;
List.Parent:=Form1;
end;
end.
SuperList.pas
unit SuperList;
interface
uses Windows, Controls, Graphics, Classes, Messages, SysUtils, StdCtrls, Forms;
type
TSuperList = class(TCustomControl)
public
DX,DY: integer;
procedure Paint; override;
constructor Create(AOwner: TComponent); override;
procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
procedure CreateParams(var Params: TCreateParams); override;
published
property TabStop default true;
property Align;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Marus', [TSuperList]);
end;
procedure TSuperList.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or WS_VSCROLL;
end;
procedure TSuperList.WMLButtonDown(var Message: TWMLButtonDown);
begin
DX:=Message.XPos;
DY:=Message.YPos;
Invalidate;
inherited;
end;
constructor TSuperList.Create(AOwner: TComponent);
begin
inherited;
DoubleBuffered:=true;
TabStop:=true;
Color:=clBtnFace;
BevelKind:=bkFlat;
Width:=200; Height:=100;
DX:=50; DY:=50;
end;
procedure TSuperList.Paint;
begin
Canvas.Brush.Color:=clWindow;
Canvas.FillRect(Canvas.ClipRect);
Canvas.TextOut(10,10,'Press left mouse button !');
Canvas.Brush.Color:=clRed;
Canvas.Pen.Color:=clBlue;
Canvas.Rectangle(DX,DY,DX+30,DY+20);
end;
end.