Author: Lou Adler
Shaking a Form
Answer:
Solve 1:
Just put a button in your form and insert these commands in the OnClick Event !
1 2 procedure TForm1.Button1Click(Sender: TObject);
3 var4 N: Integer; //Counter5 TL, TT: Integer; //Backup for LEFT and TOP of teh FORM6 begin7 TL := Left; //Backups Left of the Form8 TT := Top; //Backups Top of the Form9 //*********************************************************************10 for N := 1 to 40 do11 begin//Counter Time12 Left := (TL - 10) + (Random(20)); {Shake Range in Horizontal Driection}13 Top := (TT - 10) + (Random(20)); {Shake Range in Vertical Driection}14 end;
15 //*********************************************************************16 Left := TL; //Restores Left of the Form17 Top := TT; //Restores Top of the Form18 end;
19 20 21 Solve 2:
22 23 var24 iipt: Integer;
25 26 procedure Tform1.FormCreate;
27 begin28 iipt := Form1.Left;
29 end;
30 31 procedure TForm1.Button2Click(Sender: TObject);
32 var33 so: Integer;
34 begin35 so := 0;
36 repeat37 if Form1.Left = iipt - 10 then38 begin39 so := so + 1;
40 repeat41 Form1.Left := Form1.Left + 1;
42 until Form1.Left = iipt
43 end44 else45 repeat46 Form1.Left := Form1.Left - 1;
47 until Form1.Left = iipt - 10;
48 until so = 2;
49 end;
50 51 52 Solve 3:
53 54 for i := 2 to 7 do55 begin56 for j := 0 to 10 do57 begin58 if int(int((i - 1) / 2) / 2) * 2 = int((i - 1) / 2) then59 frmMain.Left := frmMain.Left + 1
60 else61 frmMain.Left := frmMain.Left - 1;
62 end;
63 end;