Link to home
Start Free TrialLog in
Avatar of daneb
daneb

asked on

I wona side form acros the screen


I wona  side form acros the screen after i click on
 button and stop in the center of screen
ASKER CERTIFIED SOLUTION
Avatar of ILE
ILE

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hello daneb, you did not give much information, but here is some code that will move your form to the center of the Screen, you need to add a TTimer and One button to your form. You did not say anything about relative positioning, but I used trigonometry for that.


first add    Math    to your uses clause -


  private
    { Private declarations }
    EndPos, StartPos, Mover: TPoint;
    Radian1: Extended;
    PixelMov: Integer;



procedure TForm1.but_MoveFormClick(Sender: TObject);
begin
{this is the button click}
StartPos.x := Left;
StartPos.y := Top;
EndPos.x := (Screen.Width div 2)- (Width div 2);
EndPos.y := (Screen.Height div 2) - (Height div 2);
Mover.x := 0;
Mover.y := Round(Sqrt(SumOfSquares([abs(EndPos.y-StartPos.y),abs(EndPos.x-StartPos.x)]))) div PixelMov;
Radian1 := DegToRad(180 * (1 + ArcTan2(EndPos.y-StartPos.y, EndPos.x-StartPos.x) / Pi));
PixelMov := 8;
Timer3.Interval := 55;
{the PixelMov and the length of the timer Interval will determin
the speed of movement}
Timer3.Enabled := True;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
begin
SetBounds(Round(StartPos.x-Cos(Radian1)*(PixelMov*Mover.x)),
  Round(StartPos.y-Sin(Radian1)*(PixelMov*Mover.x)), Width, Height);
Inc(Mover.x);
if (Mover.x > Mover.y) or (Mover.x > 3000) then
  begin
  Timer3.Enabled := False;
  SetBounds(EndPos.x, EndPos.y, Width, Height)
  end;
end;


- - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - -

ask question if you need more information