WM的跑表程序

自己的Moto Q8用了3年了,今天收拾了一下,看那样子再用一年也没问题。记得这是3年前买来做WM测试手机的,可随着WM的退出历史舞台,我也有一年多没有写它的程序了。既然还要继续用我的小Q,那么再收拾一下记忆,找一找几年前自己做过的东西,分享一下历史。

首先就要提一提这个跑表程序了,记得有一天晚上要测心跳,可是没有秒表。想想还是挺好笑,怎么说小Q也是智能手机,居然没有提供秒表。好吧,那就自己来写吧。

界面很简单的,时分秒,开始暂停等功能,简单明了。

下面就是历史的代码,是用C#写的。

///项目名称:跑表
///作者:lincyang
///时间:2009-10-13
///备注:昨晚想测心跳,苦于没有秒表,今天抽空写一个

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace StopWatch
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        //用几个全局变量做暂停功能
        Int16 iHour, iMin, iSec, iMS, spsec_start;
        //byte spsec_start;

        //开始与停止
        private void menuItem1_Click(object sender, EventArgs e)
        {
            if (menuItem1.Text == "Start")
            {
                menuItem1.Text = "Stop";
                menuItem2.Text = "Reset";
                timer1.Enabled = true;
            }
            else
            {
                menuItem1.Text = "Start";
                //menuItem2.Text = "Exit";
                timer1.Enabled = false;
            }
            spsec_start = (Int16)DateTime.Now.Second;
        }

        //Timer  interval 100
        private void timer1_Tick(object sender, EventArgs e)
        {
            iMS += 100;
            if (iMS == 1000)//1秒,进位
            {
                iSec += 1;
                iMS = 0;
                //每隔7 秒与系统时间(秒) 同步, 减少计时误差
                if (iSec != 0 & spsec_start % 7 ==0)
                {
                    if (DateTime.Now.Second > spsec_start)
                        iSec = (Int16)(DateTime.Now.Second - spsec_start);
                    else
                        iSec = (Int16)(DateTime.Now.Second + 60 - spsec_start);
                }

                //跑表累计时间 60秒进位
                if (iSec == 60)
                {
                    iMin += 1;
                    iSec = 0;
                    //60分钟进位
                    if (iMin == 60)
                    {
                        iHour += 1;
                        iMin = 0;
                    }
                }
            }

            //显示
            lblHour.Text = iHour.ToString("00");
            lblMin.Text = iMin.ToString("00");
            lblSec.Text = iSec.ToString("00");
            lblMS.Text = iMS.ToString("0");
        }

        //复位与退出
        private void menuItem2_Click(object sender, EventArgs e)
        {
            //如果跑表在计时中, 按本键无效。
            if (menuItem1.Text == "Start")
            {
                if (menuItem2.Text == "Reset")
                {
                    timer1.Enabled = false;
                    iHour = iMin = iSec = iMS = 0;
                    lblHour.Text = lblMin.Text = lblSec.Text = "00";
                    lblMS.Text = "0";
                    menuItem2.Text = "Exit";
                }
                else
                {
                    Int16 a = (Int16)MessageBox.Show("r u sure Exit?", "HeartWacth", MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    if (a == 1)
                        this.Dispose();
                    menuItem2.Text = "Reset";
                }
            }
        }
    }
}


记得第一版是用VB写的,代码是找到了,这个历史更早。童鞋们,还记得这些语法么?

 Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        If MenuItem1.Text = "开始" Then
            MenuItem1.Text = "暂停"
            Timer1.Enabled = True
        Else
            MenuItem1.Text = "开始"
            Timer1.Enabled = False
        End If
        spsec_start = Date.Now.Second
    End Sub

    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        ' 清零: 如果跑表在计时中, 按本键无效。
        Dim a As Int16
        If MenuItem1.Text = "开始" Then
            If MenuItem2.Text = "复位" Then
                Timer1.Enabled = False
                myhour = 0 : mymin = 0 : mysec = 0 : myms = 0
                TextBox1.Text = "00" : TextBox2.Text = "00"
                TextBox3.Text = "00" : TextBox4.Text = "0"
                MenuItem2.Text = "退出"
            Else
                ' 退出本程序? 按确定键, a 为1; 按取消键, a 为2。
                a = MessageBox.Show("退出本程序? ", "SP 简易跑表", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

                If a = 1 Then Me.Dispose()
                MenuItem2.Text = "复位"
            End If
        End If
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        myms = myms + 100 '100 就是定时器Timer1 的Interval 属性值。
        If myms = 1000 Then
            mysec = mysec + 1 : myms = 0
            ' 每隔7 秒与系统时间(秒) 同步, 减少计时误差
            If mysec <> 0 And mysec Mod 7 = 0 Then
                If Date.Now.Second > spsec_start Then
                    mysec = Date.Now.Second - spsec_start
                Else
                    mysec = Date.Now.Second + 60 - spsec_start
                End If
            End If
            ' 跑表累计时间
            If mysec = 60 Then
                mymin = mymin + 1 : mysec = 0
                If mymin = 60 Then
                    myhour = myhour + 1 : mymin = 0
                End If
            End If
        End If
        TextBox1.Text = myhour.ToString
        TextBox2.Text = mymin.ToString
        TextBox3.Text = mysec.ToString
        TextBox4.Text = Mid(myms.ToString, 1, 1)
    End Sub


源码已经上传到下载区了,告诉我稍后会显示,等了半个多小时了,还是没有。明天再看看,不行,就继续传。


你可能感兴趣的:(timer,object,Class,手机,vb,textbox)