Einzelnen Beitrag anzeigen

Natcree

Registriert seit: 5. Mär 2013
502 Beiträge
 
Delphi 7 Enterprise
 
#4

AW: Button Image bei Drag & Drop

  Alt 3. Dez 2013, 22:48
Ich Danke euch Habe es so gemacht
Delphi-Quellcode:
var
flastpos: TPoint;
Delphi-Quellcode:
procedure TForm1.ButtonMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
r:TRect;
begin
  if [ssLeft,ssRight]*Shift=[ssLeft,ssRight] then exit;
  with TControl(Sender) do
  begin
    flastpos:=ClientToScreen(Point(x,y));//um sicherzustellen, daß der Button auf dem Panel bleibt
    r:=Parent.ClientRect;
    r.TopLeft:=Parent.ClientToScreen(r.TopLeft);
    r.BottomRight:=Parent.ClientToScreen(r.BottomRight);
    inc(r.Left,x);
    dec(r.Right,Width-x);
    inc(r.Top,y);
    dec(r.Bottom,Height-y);
    ClipCursor(@r);
  end;
end;

procedure TForm1.ButtonMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
var
mpos:TPoint;
begin
  if [ssLeft,ssRight]*Shift=[] then exit;
  with TControl(Sender) do
  begin
    mpos:=ClientToScreen(Point(x,y));
    x:=mpos.x-flastpos.x;
    y:=mpos.y-flastpos.y;
    SetBounds(Left+x,Top+y,Width,Height);
    flastpos:=mpos;
  end;
end;

procedure TForm1.ButtonMouseUp(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
  if [ssLeft,ssRight]*Shift<>[] then exit;
  ClipCursor(nil);
end;
  Mit Zitat antworten Zitat