Shaking a form (Views: 31)
Problem/Question/Abstract: Shaking a Form Answer: Solve 1: Just put a button in your form and insert these commands in the OnClick Event ! procedure TForm1.Button1Click(Sender: TObject); var N: Integer; //Counter TL, TT: Integer; //Backup for LEFT and TOP of teh FORM begin TL := Left; //Backups Left of the Form TT := Top; //Backups Top of the Form //********************************************************************* for N := 1 to 40 do begin //Counter Time Left := (TL - 10) + (Random(20)); {Shake Range in Horizontal Driection} Top := (TT - 10) + (Random(20)); {Shake Range in Vertical Driection} end; //********************************************************************* Left := TL; //Restores Left of the Form Top := TT; //Restores Top of the Form end; Solve 2: var iipt: Integer; procedure Tform1.FormCreate; begin iipt := Form1.Left; end; procedure TForm1.Button2Click(Sender: TObject); var so: Integer; begin so := 0; repeat if Form1.Left = iipt - 10 then begin so := so + 1; repeat Form1.Left := Form1.Left + 1; until Form1.Left = iipt end else repeat Form1.Left := Form1.Left - 1; until Form1.Left = iipt - 10; until so = 2; end; Solve 3: for i := 2 to 7 do begin for j := 0 to 10 do begin if int(int((i - 1) / 2) / 2) * 2 = int((i - 1) / 2) then frmMain.Left := frmMain.Left + 1 else frmMain.Left := frmMain.Left - 1; end; end; |