?
Solved

I wona  side form acros the screen

Posted on 2003-02-24
2
Medium Priority
?
142 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
[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
  • Learn & ask questions
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 34

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 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