?
Solved

I wona  side form acros the screen

Posted on 2003-02-24
2
Medium Priority
?
145 Views
Last Modified: 2010-04-04

I wona  side form acros the screen after i click on
 button and stop in the center of screen
0
Comment
Question by:daneb
2 Comments
 
LVL 3

Accepted Solution

by:
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 35

Expert Comment

by:Slick812
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.


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
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question