1 (edited by prahousefamily 2018-11-08 04:18:32)

Topic: Example Funny Time Event For Panel Move

reference From 

http://www.schoolfreeware.com/Free_Pascal_Lazarus_App_GUI_Tutorial_12.html

Free Pascal Lazarus App Tutorial 12 - System Timer Bouncing Ball Animation - Shapes
A shape is added to the form. The shape is made into a circle, resized and colored red with the brush. A timer is added to allow the shape to move around the form. When the shape hits the side of the form the ball will bounce of the form’s side.




I try code to MVD and change Tshape To Panel

Look Little Funny Time

Screen Short
https://image.ibb.co/cggntV/2018-11-08-004.png

Open Code

var
Timer: TTimer;
procedure Form1_OnShow (Sender: string; Action: string);
begin
    Timer := TTimer.Create (nil);
    Timer.OnTimer := @OnTimer;
    Timer.Interval := 10;
    Timer.Enabled := True;
end;
procedure OnTimer;
var
G_Right: Boolean;
G_Up: Boolean;
R_Right: Boolean;
R_Up: Boolean;
Y_Right: Boolean;
Y_Up: Boolean;
begin
    if G_Up = True then
    Form1.Panel1.Top := Form1.Panel1.Top - 2
    else
    Form1.Panel1.Top := Form1.Panel1.Top + 2;
    if G_Right = True then
    Form1.Panel1.Left := Form1.Panel1.Left + 2
    else
    Form1.Panel1.Left := Form1.Panel1.Left - 2;
    if Form1.Panel1.Top <= 0 then
    G_Up := False;
    if Form1.Panel1.Top + Form1.Panel1.Height >= Form1.Height then
    G_Up := True;
    if Form1.Panel1.Left <= 0 then
    G_Right := True;
    if Form1.Panel1.Left + Form1.Panel1.Width >= Form1.Width then
    G_Right := False;
    if R_Up = True then
    Form1.Panel2.Top := Form1.Panel2.Top - 4
    else
    Form1.Panel2.Top := Form1.Panel2.Top + 4;
    if R_Right = True then
    Form1.Panel2.Left := Form1.Panel2.Left + 4
    else
    Form1.Panel2.Left := Form1.Panel2.Left - 4;
    if Form1.Panel2.Top <= 0 then
    R_Up := False;
    if Form1.Panel2.Top + Form1.Panel2.Height >= Form1.Height then
    R_Up := True;
    if Form1.Panel2.Left <= 0 then
    R_Right := True;
    if Form1.Panel2.Left + Form1.Panel2.Width >= Form1.Width then
    R_Right := False;
    if Y_Up = True then
    Form1.Panel3.Top := Form1.Panel3.Top -3
    else
    Form1.Panel3.Top := Form1.Panel3.Top +3;
    if Y_Right = True then
    Form1.Panel3.Left := Form1.Panel3.Left +3
    else
    Form1.Panel3.Left := Form1.Panel3.Left -3;
    if Form1.Panel3.Top <= 0 then
    Y_Up := False;
    if Form1.Panel3.Top + Form1.Panel3.Height >= Form1.Height then
    Y_Up := True;
    if Form1.Panel3.Left <= 0 then
    Y_Right := True;
    if Form1.Panel3.Left + Form1.Panel3.Width >= Form1.Width then
    Y_Right := False;
end;
procedure Form1_OnClose (Sender: string; Action: string);
begin
    Timer.Free;
end;
begin
end.
Post's attachments

Attachment icon TimeFunny.zip 5 kb, 19 downloads since 2018-11-07 

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: Example Funny Time Event For Panel Move

Thank you!

Dmitry.