StopWatch

StopWatch

附件

  http://download.csdn.net/detail/teststudio/6575241

 

 

 

 

 

StopWatch

主窗体UNIT

unit MainForm;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls, StdCtrls, ComCtrls;



type

  TFormMain = class(TForm)

    Button2: TButton;

    Button1: TButton;

    Panel1: TPanel;

    procedure FormCreate(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;



var

  FormMain: TFormMain;



implementation



uses Unit2, Unit3;

{$R *.dfm}



var

  frm_StopWatch: TForm2;

  frm_CountDown: TForm3;



procedure ShowStopWatch;

begin

  with frm_StopWatch do

  begin

    Parent := FormMain.Panel1;

    BorderStyle := BsNone;

    Align := alClient;

    Show;

  end;

end;



procedure ShowCountDown;

begin

  with frm_CountDown do

  begin

    Parent := FormMain.Panel1;

    BorderStyle := BsNone;

    Align := alClient;

    Show;

  end;

end;



procedure SetButtonEnabled1;

begin

  FormMain.Caption:='秒表';

  FormMain.Button1.Enabled := False;

  FormMain.Button2.Enabled := True;

end;



procedure SetButtonEnabled2;

begin

  FormMain.Caption:='倒计时';

  FormMain.Button1.Enabled := True;

  FormMain.Button2.Enabled := False;

end;



procedure TFormMain.Button1Click(Sender: TObject);

begin

  // 秒表

  SetButtonEnabled1;

  ShowStopWatch;

  frm_CountDown.Hide;

end;



procedure TFormMain.Button2Click(Sender: TObject);

begin

  SetButtonEnabled2;

  ShowCountDown;

  frm_StopWatch.Hide;



end;



procedure TFormMain.FormCreate(Sender: TObject);

begin

  frm_StopWatch := TForm2.Create(self);

  frm_CountDown := TForm3.Create(self);

  ShowStopWatch;

end;



end.

 

 主窗体FRM

object FormMain: TFormMain

  Left = 0

  Top = 0

  BorderIcons = [biSystemMenu, biMinimize]

  BorderStyle = bsSingle

  Caption = #31186#34920

  ClientHeight = 282

  ClientWidth = 243

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  FormStyle = fsStayOnTop

  OldCreateOrder = False

  Position = poDesktopCenter

  OnCreate = FormCreate

  PixelsPerInch = 96

  TextHeight = 13

  object Button2: TButton

    Left = 120

    Top = 255

    Width = 121

    Height = 25

    Caption = #20498#35745#26102

    TabOrder = 0

    OnClick = Button2Click

  end

  object Button1: TButton

    Left = 2

    Top = 255

    Width = 119

    Height = 25

    Caption = #31186#34920

    Enabled = False

    TabOrder = 1

    OnClick = Button1Click

  end

  object Panel1: TPanel

    Left = 2

    Top = 2

    Width = 239

    Height = 249

    Caption = 'Panel1'

    TabOrder = 2

  end

end
主窗体FRM

 

 

 

StopWatch

//秒表Unit2

unit Unit2;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls, StdCtrls, ComCtrls, Menus,

     Buttons;



type

  TForm2 = class(TForm)

    Timer1: TTimer;

    ListView1: TListView;

    Label2: TLabel;

    Timer2: TTimer;

    Label1: TLabel;

    Button1: TButton;

    Button2: TButton;

    procedure Timer1Timer(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Timer2Timer(Sender: TObject);

    procedure FormClick(Sender: TObject);

  private

    { Private declarations }

    procedure AddListViewItem;

    procedure CleanLabel2;

    procedure tglForm;

  public

    { Public declarations }

  end;



var

  Form2: TForm2;



implementation



{$R *.dfm}



procedure TForm2.Button1Click(Sender: TObject);

begin

  if Button1.Caption = '开始' then

  begin

    Button1.Caption := '停止';

    Button2.Caption := '计次';

    Timer1.Enabled := True;

    Timer2.Enabled := True;

    // Button1.Color:=clRed;

  end

  else

  begin

    Button1.Caption := '开始';

    Button2.Caption := '复位';

    Timer1.Enabled := False;

    Timer2.Enabled := False;

   // Button1.Color:=clGreen;

  end;

end;



procedure TForm2.AddListViewItem;

var

  i: Integer;

begin



  i := ListView1.Items.Count + 1;

  with ListView1.Items.Add do

  begin

    Caption := IntToStr(i);

    SubItems.Add(Label2.Caption);

  end;

  SendMessage(ListView1.Handle, WM_VSCROLL, SB_BOTTOM, 0);

end;



var

  h: Integer = 0;

  m: Integer = 0;

  s: Integer = 0;



  h1: Integer = 0;

  m1: Integer = 0;

  s1: Integer = 0;



procedure TForm2.CleanLabel2;

begin

  if Button2.Caption = '计次' then

  begin

    h := 0;

    m := 0;

    s := 0;

    Label2.Caption := Format('%.2d:%.2d:%.2d', [h, m, s]);

  end;



  if Button2.Caption = '复位' then

  begin

    h := 0;

    m := 0;

    s := 0;



    h1 := 0;

    m1 := 0;

    s1 := 0;

    Label1.Caption := Format('%.2d:%.2d:%.2d', [h1, m1, s1]);

    Label2.Caption := Format('%.2d:%.2d:%.2d', [h, m, s]);

    ListView1.Clear;

  end;



end;



procedure TForm2.tglForm;

begin

  if Height = 341 then

    Height := 122

  else

    Height := 341;

end;



procedure TForm2.FormClick(Sender: TObject);

begin

  tglForm;

end;



procedure TForm2.Button2Click(Sender: TObject);

begin

  AddListViewItem;

  CleanLabel2;

end;



procedure TForm2.Timer1Timer(Sender: TObject);

begin

  inc(s1);

  if s1 >= 60 then

  begin

    inc(m1);

    s1 := 0;

  end;

  if m1 >= 60 then

  begin

    inc(h1);

    m1 := 0;

  end;

  Label1.Caption := Format('%.2d:%.2d:%.2d', [h1, m1, s1]);

end;



procedure TForm2.Timer2Timer(Sender: TObject);

begin

  inc(s);

  if s >= 60 then

  begin

    inc(m);

    s := 0;

  end;

  if m >= 60 then

  begin

    inc(h);

    m := 0;

  end;

  Label2.Caption := Format('%.2d:%.2d:%.2d', [h, m, s]);



end;



end.

 

 

object Form2: TForm2

  Left = 0

  Top = 0

  BorderIcons = [biSystemMenu, biMinimize]

  Caption = #31186#34920

  ClientHeight = 204

  ClientWidth = 242

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clNone

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  Position = poDesktopCenter

  OnClick = FormClick

  DesignSize = (

    242

    204)

  PixelsPerInch = 96

  TextHeight = 13

  object Label2: TLabel

    Left = 168

    Top = 24

    Width = 62

    Height = 19

    AutoSize = False

    Caption = '00:00:00'

    Color = clBackground

    Font.Charset = DEFAULT_CHARSET

    Font.Color = clBlack

    Font.Height = -15

    Font.Name = 'Tahoma'

    Font.Style = []

    ParentColor = False

    ParentFont = False

  end

  object Label1: TLabel

    Left = 8

    Top = 10

    Width = 145

    Height = 33

    AutoSize = False

    Caption = '00:00:00'

    Font.Charset = ANSI_CHARSET

    Font.Color = clNone

    Font.Height = -29

    Font.Name = #24494#36719#38597#40657

    Font.Style = [fsBold]

    ParentFont = False

  end

  object ListView1: TListView

    Left = 8

    Top = 80

    Width = 226

    Height = 116

    Anchors = [akLeft, akTop, akRight, akBottom]

    BorderStyle = bsNone

    Color = clCream

    Columns = <

      item

        Caption = #35745#27425

        Width = 40

      end

      item

        Caption = #26102#38388

        Width = 140

      end>

    ColumnClick = False

    Font.Charset = ANSI_CHARSET

    Font.Color = clNone

    Font.Height = -13

    Font.Name = #24494#36719#38597#40657

    Font.Style = []

    FlatScrollBars = True

    HideSelection = False

    MultiSelect = True

    RowSelect = True

    ParentFont = False

    TabOrder = 0

    ViewStyle = vsReport

  end

  object Button1: TButton

    Left = 8

    Top = 49

    Width = 105

    Height = 25

    Caption = #24320#22987

    Default = True

    TabOrder = 1

    OnClick = Button1Click

  end

  object Button2: TButton

    Left = 119

    Top = 49

    Width = 111

    Height = 25

    Cancel = True

    Caption = #22797#20301

    TabOrder = 2

    OnClick = Button2Click

  end

  object Timer1: TTimer

    Enabled = False

    OnTimer = Timer1Timer

    Left = 88

    Top = 112

  end

  object Timer2: TTimer

    Enabled = False

    OnTimer = Timer2Timer

    Left = 136

    Top = 112

  end

end
Unit2.DFM

 

 

 

StopWatch

//倒计时单元文件
unit Unit3;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls, StdCtrls, Spin;



type

  TForm3 = class(TForm)

    Timer1: TTimer;

    Label1: TLabel;

    Button1: TButton;

    Panel1: TPanel;

    SpinEdit1: TSpinEdit;

    SpinEdit2: TSpinEdit;

    SpinEdit3: TSpinEdit;

    Timer2: TTimer;

    ComboBox1: TComboBox;

    procedure Timer1Timer(Sender: TObject);

    procedure Button1Click(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure ComboBox1CloseUp(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;



var

  Form3: TForm3;



implementation



uses MmSystem;

{$R SOUND.RES}

{$R *.dfm}



var

  h1: Integer = 0;

  m1: Integer = 0;

  s1: Integer = 0;

  SoundID: PChar = 'RING3';



procedure TForm3.Button1Click(Sender: TObject);

begin

  h1 := SpinEdit1.Value;

  m1 := SpinEdit2.Value;

  s1 := SpinEdit3.Value;



  if Button1.Caption = '开始' then

  begin

    Button1.Caption := '停止';

    Timer1.Enabled := True;

    panel1.Visible:=False;

    label1.Visible:=True;

  end

  else

  begin

    Button1.Caption := '开始';

    Timer1.Enabled := false;

    PlaySound(0, 0, 0);

    panel1.Visible:=True;

    label1.Visible:=False;

  end;



end;



procedure TForm3.ComboBox1CloseUp(Sender: TObject);

begin

  case ComboBox1.ItemIndex of

    0:

      SoundID := 'RING1';

    1:

      SoundID := 'RING2';

    2:

      SoundID := 'RING3';

  end;

end;



procedure TForm3.FormCreate(Sender: TObject);

begin

  ComboBox1.ItemIndex := 2;

  label1.Left:=8;

  Label1.Top:=20;

  label1.Visible:=False;

end;



procedure TForm3.Timer1Timer(Sender: TObject);

begin



  if (h1 <= 0) and (m1 <= 0) and (s1 <= 0) then

  begin

    Timer1.Enabled := false;

    Button1.Caption := '结束';

    label1.Caption:='00:00:00';

    PlaySound(SoundID, 0, snd_ASync or snd_Loop or snd_Resource );

    exit;

  end;



  Dec(s1);

  if s1 <= 0 then

  begin

    if (m1 > 0) or (h1 > 0) then

    begin

      Dec(m1);

      s1 := 60;

    end;

  end;

  if m1 < 0 then

  begin

    if h1 > 0 then

    begin

      Dec(h1);

      m1 := 60;

    end;

  end;



  Label1.Caption := Format('%.2d:%.2d:%.2d', [h1, m1, s1]);

end;



end.

 

object Form3: TForm3

  Left = 0

  Top = 0

  Caption = #20498#35745#26102

  ClientHeight = 217

  ClientWidth = 238

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  Position = poDesktopCenter

  OnCreate = FormCreate

  PixelsPerInch = 96

  TextHeight = 13

  object Label1: TLabel

    Left = 8

    Top = 151

    Width = 222

    Height = 42

    Alignment = taCenter

    AutoSize = False

    Caption = '00:00:00'

    Font.Charset = ANSI_CHARSET

    Font.Color = clNone

    Font.Height = -29

    Font.Name = #24494#36719#38597#40657

    Font.Style = [fsBold]

    ParentFont = False

    Transparent = True

  end

  object Button1: TButton

    Left = 8

    Top = 82

    Width = 222

    Height = 39

    Caption = #24320#22987

    Default = True

    TabOrder = 0

    OnClick = Button1Click

  end

  object Panel1: TPanel

    Left = 8

    Top = 8

    Width = 222

    Height = 68

    BevelOuter = bvNone

    TabOrder = 1

    object SpinEdit1: TSpinEdit

      Left = 8

      Top = 11

      Width = 49

      Height = 22

      MaxValue = 9999

      MinValue = 0

      TabOrder = 0

      Value = 0

    end

    object SpinEdit2: TSpinEdit

      Left = 63

      Top = 11

      Width = 49

      Height = 22

      MaxValue = 60

      MinValue = 0

      TabOrder = 1

      Value = 0

    end

    object SpinEdit3: TSpinEdit

      Left = 118

      Top = 11

      Width = 49

      Height = 22

      MaxValue = 60

      MinValue = 0

      TabOrder = 2

      Value = 60

    end

    object ComboBox1: TComboBox

      Left = 8

      Top = 39

      Width = 201

      Height = 21

      Style = csDropDownList

      ImeName = #20013#25991' - QQ'#20116#31508#36755#20837#27861

      TabOrder = 3

      OnCloseUp = ComboBox1CloseUp

      Items.Strings = (

        'RING1'

        'RING2'

        'RING3')

    end

  end

  object Timer1: TTimer

    Enabled = False

    OnTimer = Timer1Timer

    Left = 176

    Top = 176

  end

  object Timer2: TTimer

    Enabled = False

    Left = 176

    Top = 224

  end

end
倒计时窗体文件

 



你可能感兴趣的:(Stop)