A SDP Code Tutorial.....get inspired!

The Walking Label

 

dl.gif (6779 bytes)Source code

 

{
The Walking label
A SDP Code Tutorial......get inspired!

This application demonstrate the use of the following components :
- TTimer component
- TTrackbar component
- TPopupMenu component
- TScreen object

Application description :
This application has a label which moves across you screen like
a bulletinboard. With the trackbar you can adjust the speed.
Use the right mouse click to invoke the popupmenu where
you can set the application in the Bulletinboard- or settingsmode.
Using the settings you can make, Full screen / Top or Bottom.

(c)BeenSoft 06-03-2000 All rights reserved.
beensoft@yahoo.com
http://surf.to/beensoft
}

unit Unit_Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ComCtrls, Buttons, Menus, NumEdit;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Panel1: TPanel;
    TrackBar1: TTrackBar;
    lblPosition: TLabel;
    Label2: TLabel;
    PopupMenu1: TPopupMenu;
    BulletinBoard1: TMenuItem;
    Settings1: TMenuItem;
    EditText: TEdit;
    lblBBText: TLabel;
    Label1: TLabel;
    cbxFullscreen: TCheckBox;
    rgPosition: TRadioGroup;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
    procedure BulletinBoard1Click(Sender: TObject);
    procedure Settings1Click(Sender: TObject);
    procedure EditTextChange(Sender: TObject);
    procedure cbxFullscreenClick(Sender: TObject);
    procedure rgPositionClick(Sender: TObject);
  private
    { Private declarations }
    FOriginHeight : Integer;
    FOriginWidht : Integer;
  public
    { Public declarations }
    property OriginHeight : Integer read FOriginHeight write FOriginHeight;
    property OriginWidth : Integer read FOriginWidht write FOriginWidht;
  end;

var
  Form1: TForm1;
  Screen : TScreen;
const
  POSITIONCHANGE = 5;
//This constant determines the amount of pixels the label is moved per Timertick
//A greater number means moving faster, but on lower speed
//it will get a bit hacky 5 is just fine I think


implementation

{$R *.DFM}
//////////////////////////////////////////////////////////
// Create event
// - Initialize the components properties
//////////////////////////////////////////////////////////
procedure TForm1.FormCreate(Sender: TObject);
begin
  OriginHeight := Form1.Height;
  Originwidth := Form1.Width;
  lblBBText.Caption := EditText.Text;
  TrackBar1.Position := 1; Timer1.Interval := 1;
  Settings1.Checked := True;
end;


//////////////////////////////////////////////////////////
// OnTimer event
// - Executes for every timer tick
// Time between ticks are set with the TTimers Interval prop
//////////////////////////////////////////////////////////
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  If lblBBText.Left > 0 - lblBBText.Width then
     lblBBText.Left:=lblBBText.Left - POSITIONCHANGE
  else
  begin
     lblBBText.Left:=Form1.Width - 100;//376;
  end;
end;

//////////////////////////////////////////////////////////
// Tracbar Change event
// - Change the speed of the Label
//   by setting the Timer Interval to the TrackBar position value
//   Value 1 to 500
//////////////////////////////////////////////////////////
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  Timer1.Interval :=  TrackBar1.Position;
  lblPosition.caption := IntToStr(TrackBar1.Position);
end;


//////////////////////////////////////////////////////////
// Popup menu events
//////////////////////////////////////////////////////////
procedure TForm1.BulletinBoard1Click(Sender: TObject);
begin
  Form1.Height := Panel1.Height;  // Only the panel visible
  Form1.BorderStyle := bsNone;    // No border
  BulletinBoard1.Checked := True; // Check the menuItem
  Settings1.Checked := False;     // UnCheck the other menuItem
end;

procedure TForm1.Settings1Click(Sender: TObject);
begin
  Form1.Height := OriginHeight;
  Form1.BorderStyle := bsSingle;
  BulletinBoard1.Checked := False;
  Settings1.Checked := True;
end;

//////////////////////////////////////////////////////////
// Edit Text Change event
// Changes are immediately passed to the lblBBText label
//////////////////////////////////////////////////////////
procedure TForm1.EditTextChange(Sender: TObject);
begin
  lblBBText.Caption := EditText.Text;
end;

//////////////////////////////////////////////////////////
// cbxFullScreen Click event
//////////////////////////////////////////////////////////
procedure TForm1.cbxFullscreenClick(Sender: TObject);
begin
  if cbxFullScreen.checked then    // Let's go full screen mode
  begin
    Form1.Width := Screen.Width;   // Get the width of the screen
    Form1.Left := 0;
    case rgPosition.ItemIndex of   //Position Top/Bottom screen
      0 : Form1.Top := 0;          //Top
      1 : Form1.Top := (Screen.Height - (Panel1.Height + TrackBar1.Height));//Bottom
    end;
  end
  else
  begin                            //Reset to Original Width
    Form1.Width := OriginWidth;
  end
end;

//////////////////////////////////////////////////////////
// rgPosition Click event
// - If cbxFullScreen is checked then set screen values
//   by executing the cbxFullScreen onclickevent
//////////////////////////////////////////////////////////
procedure TForm1.rgPositionClick(Sender: TObject);
begin
  if cbxFullScreen.Checked then   
    cbxFullScreenClick(Sender);
end;

end.