Delphi-Quellcode:
TALine = class (TCustomControl)
constructor Create(AOwner: TComponent);
procedure MoveControl(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
protected
procedure Paint;override;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
published
end;
...
constructor TALine.Create(AOwner: TComponent);
var i:integer;
begin
inherited Create(AOwner);
self.OnMouseDown:= MoveControl;
self.Width:=100;
self.Visible:=true;
self.Height:=5;
end;
procedure TALine.Paint;
var
i:integer;
s:string;
save:tcolor;
begin
inherited;
//save:=self.Canvas.Brush.Color;
self.Canvas.Brush.Color:=clblack;
self.Canvas.FillRect(Rect(0,0,self.Width,self.Height));
//self.Canvas.Brush.Color:=save;
end;
procedure TALine.MoveControl(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ssCtrl in Shift then begin
ReleaseCapture;
(Sender as twincontrol).perform(WM_SysCommand, $F012, 0);
end;
end;
Das sollte eine 5px dicke schwartze Line mit einer Weite von 100px zeichnen die mit der Strg und der Maus Verschiebbar ist.