Solved

# I wona  side form acros the screen

Posted on 2003-02-24
Medium Priority
142 Views

I wona  side form acros the screen after i click on
button and stop in the center of screen
0
Question by:daneb
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 3

Accepted Solution

ILE earned 280 total points
ID: 8013237
wery easy

if i corectly andrestand what u wont

this is agood solution

get one timer component
and do the folowing

procedure TForm1.Timer1Timer(Sender: TObject);
var xc,yc:integer;
begin
xc:=(screen.width-form1.width) div 2; yc:=(screen.height-form1.height) div 2;
if form1.top>yc then form1.top:=form1.top-1 else form1.Top:=form1.Top+1;
if form1.left>xc then form1.left:=form1.left-1 else form1.left:=form1.left+1;
if abs(form1.Top+form1.Left-xc-yc)<3 then timer1.enabled:=false;  {this is stop sliding}
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
timer1.enabled:=true;
end;

0

LVL 34

Expert Comment

ID: 8013399
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.

private
{ Private declarations }
EndPos, StartPos, Mover: TPoint;
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;
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
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;

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

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…