using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; //添加以下命名空间
using System.IO;
using System.Reflection;
using System.Resources;
namespace 帅的计时器哈哈
{
public partial class Form1 : Form
{
private int _nowsecond = ;
//类字段:冒号控制标志
private Boolean _colonFlag = true; //数码管位图数组
private Bitmap[] _bmpShow = new Bitmap[]; //自定义方法:由显示字符获取对应的数码管位图
private Image GetResourceImage(string displayStr)
{
if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == "")
return _bmpShow[];
else if (displayStr == ".")
return _bmpShow[];
else if (displayStr == ":")
return _bmpShow[];
else
return _bmpShow[];
} public Form1()
{
InitializeComponent();
//初始化时间计数值(秒)
_nowsecond = ;
//装载数码管位图文件(注意:要保证Debug目录下有images子目录及bmp文件,否则会报错)
_bmpShow[] = new Bitmap("images/0.bmp");
_bmpShow[] = new Bitmap("images/1.bmp");
_bmpShow[] = new Bitmap("images/2.bmp");
_bmpShow[] = new Bitmap("images/3.bmp");
_bmpShow[] = new Bitmap("images/4.bmp");
_bmpShow[] = new Bitmap("images/5.bmp");
_bmpShow[] = new Bitmap("images/6.bmp");
_bmpShow[] = new Bitmap("images/7.bmp");
_bmpShow[] = new Bitmap("images/8.bmp");
_bmpShow[] = new Bitmap("images/9.bmp");
_bmpShow[] = new Bitmap("images/dot1.bmp");
_bmpShow[] = new Bitmap("images/dot2.bmp");
_bmpShow[] = new Bitmap("images/blank.bmp");
} private void label3_Click(object sender, EventArgs e)
{ } //按钮"开始"的Click事件响应方法
private void buttonStart_Click(object sender, EventArgs e)
{
label2.Visible = false;
_nowsecond = ;
//启动定时器
timer1.Enabled = true; timer2.Enabled = true; //初始化时间计数值
labelHour.Text = "";
labelMinute.Text = "";
labelSecond.Text = "";
labelColon1.Visible = true;
labelColon2.Visible = true;
//启用或禁用有关按钮
buttonStart.Enabled = false; buttonPauseContinue.Enabled = true; buttonStop.Enabled = true;
//改变按钮文字
buttonPauseContinue.Text = "暂停";
buttonStart.BackColor=buttonStart.BackColor == Color.Blue ? Color.Yellow : Color.Blue;
//冒号控制标志设置为true
_colonFlag = true;
//隐藏冒号
pictureBoxColon1.Image = GetResourceImage(" ");
pictureBoxColon2.Image = GetResourceImage(" "); } private void timer1_Tick(object sender, EventArgs e)
{
_nowsecond++;
int hour = _nowsecond / ;
int minute = (_nowsecond % ) / ;
int second = (_nowsecond % ) % ; if(hour<=)
labelHour.Text=""+hour.ToString();
else labelHour.Text = hour.ToString();
if(minute<=)
labelMinute.Text = "" + minute.ToString();
else labelMinute.Text = minute.ToString();
if(second<=)
labelSecond.Text = "" + second.ToString();
else labelSecond.Text = second.ToString();
//显示当前的秒
this.pictureBoxSecond1.Image = GetResourceImage((second / ).ToString());
this.pictureBoxSecond2.Image = GetResourceImage((second % ).ToString());
//显示当前的分
this.pictureBoxMinute1.Image = GetResourceImage((minute / ).ToString());
this.pictureBoxMinute2.Image = GetResourceImage((minute % ).ToString());
//显示当前的小时
this.pictureBoxHour1.Image = GetResourceImage((hour / ).ToString());
this.pictureBoxHour2.Image = GetResourceImage((hour % ).ToString()); } private void labelHour_Click(object sender, EventArgs e)
{ } private void labelMinute_Click(object sender, EventArgs e)
{ } private void labelSecond_Click(object sender, EventArgs e)
{ } //Timer2定时器的Tick事件响应方法
private void timer2_Tick(object sender, EventArgs e)
{
//让中间的冒号闪烁起来
if (labelColon1.Visible == true)
{
labelColon1.Visible = false;
labelColon2.Visible = false;
}
else
{
labelColon1.Visible = true;
labelColon2.Visible = true;
}
//切换冒号显示控制标志
_colonFlag = !_colonFlag; //判断冒号控制标志是否为true
if (_colonFlag == true)
{
pictureBoxColon1.Image = GetResourceImage(" ");
pictureBoxColon2.Image = GetResourceImage(" ");
}
else
{
pictureBoxColon1.Image = GetResourceImage(":");
pictureBoxColon2.Image = GetResourceImage(":");
}
} private void buttonStart_MouseDown(object sender, MouseEventArgs e)
{
} private void buttonStart_KeyPress(object sender, KeyPressEventArgs e)
{ } private void Form1_Load(object sender, EventArgs e)
{
buttonStart.Enabled = true;
buttonPauseContinue.Enabled = false;
buttonStop.Enabled = false;
buttonPauseContinue.Text = "暂停";
labelColon1.Visible = true;
labelColon2.Visible = true;
label2.Visible = false;
//初始化所有ImageBox控件的初始位图
pictureBoxHour1.Image = GetResourceImage("");
pictureBoxHour2.Image = GetResourceImage("");
pictureBoxMinute1.Image = GetResourceImage("");
pictureBoxMinute2.Image = GetResourceImage("");
pictureBoxSecond1.Image = GetResourceImage("");
pictureBoxSecond2.Image = GetResourceImage("");
pictureBoxColon1.Image = GetResourceImage(":");
pictureBoxColon2.Image = GetResourceImage(":"); } private void buttonStop_Click(object sender, EventArgs e)
{
_nowsecond = ;
timer1.Enabled = false;
timer2.Enabled = false;
buttonStart.Enabled = true; buttonPauseContinue.Enabled = false; buttonStop.Enabled = false;
buttonPauseContinue.Text = "暂停";
labelColon2.Visible = true;
labelColon1.Visible = true;
buttonStart.BackColor = Color.Yellow;
labelHour.Text = "";
labelMinute.Text = "";
labelSecond.Text = "";
label2.Visible = true;
//冒号控制标志设置为true
_colonFlag = true;
//显示冒号
pictureBoxColon1.Image = GetResourceImage(":");
pictureBoxColon2.Image = GetResourceImage(":"); //清空时间计数值(秒)
_nowsecond = ;
pictureBoxHour1.Image = GetResourceImage("");
pictureBoxHour2.Image = GetResourceImage("");
pictureBoxMinute1.Image = GetResourceImage("");
pictureBoxMinute2.Image = GetResourceImage("");
pictureBoxSecond1.Image = GetResourceImage("");
pictureBoxSecond2.Image = GetResourceImage("");
pictureBoxColon1.Image = GetResourceImage(":");
pictureBoxColon2.Image = GetResourceImage(":");
} private void buttonPauseContinue_Click(object sender, EventArgs e)
{
if (buttonPauseContinue.Text== "暂停")
{
labelColon2.Visible = true;
labelColon1.Visible = true;
timer1.Enabled = false;
timer2.Enabled = false;
buttonPauseContinue.Text = "继续";
}
else
{
labelColon2.Visible = true;
labelColon1.Visible = true;
timer1.Enabled = true;
timer2.Enabled = true;
buttonPauseContinue.Text = "暂停";
}
pictureBoxColon1.Image = GetResourceImage(":");
pictureBoxColon2.Image = GetResourceImage(":");
} private void Form1_Move(object sender, EventArgs e)
{
//停靠屏幕左右边框
int screenRight = Screen.PrimaryScreen.Bounds.Right;
int formRight = this.Left + this.Size.Width;
if (Math.Abs(screenRight - formRight) <= )
this.Left = screenRight - this.Size.Width;
if (Math.Abs(this.Left) <= )
this.Left = ; //停靠屏幕上下边框
int screenBottom = Screen.PrimaryScreen.Bounds.Bottom;
int formBottom = this.Top + this.Size.Height;
if (Math.Abs(screenBottom - formBottom) <= )
this.Top = screenBottom - this.Size.Height;
if (Math.Abs(this.Top) <= )
this.Top = ;
} private void pictureBox2_Click(object sender, EventArgs e)
{ } private void pictureBox5_Click(object sender, EventArgs e)
{ } private void pictureBoxHour1_Click(object sender, EventArgs e)
{ }
}
}

C#计数器的更多相关文章

  1. Sql Server 内存相关计数器以及内存压力诊断

    在数据库服务器中,内存是数据库对外提供服务最重要的资源之一, 不仅仅是Sql Server,包括其他数据库,比如Oracle,MySQL等,都是一类非常喜欢内存的应用. 在Sql Server服务器中 ...

  2. 用application实现一个网页的浏览计数器

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  3. [LeetCode] Design Hit Counter 设计点击计数器

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  4. SQL Server需要监控哪些计数器

    常规计数器 收集操作系统服务器的服务器性能信息,包括Processor.磁盘.网络.内存 Processor 处理器 1.1 % Processor Time指处理器用来执行非闲置线程时间的百分比.通 ...

  5. javascript 转盘抽奖代码和计数器代码

    要介绍了javascript圆盘抽奖程序实现原理和完整代码例子,需要的朋友可以参考下  看到网页上有不少大转盘抽奖的应用,心血来潮也想弄个.于是找了点资料自己研究...  效果预览: 一.模拟抽奖的实 ...

  6. Hadoop学习笔记—7.计数器与自定义计数器

    一.Hadoop中的计数器 计数器:计数器是用来记录job的执行进度和状态的.它的作用可以理解为日志.我们通常可以在程序的某个位置插入计数器,用来记录数据或者进度的变化情况,它比日志更便利进行分析. ...

  7. $\LaTeX$笔记:Section 编号方式(数字、字母、罗马)&计数器计数形式修改

    $\LaTeX$系列根目录: Latex学习笔记-序 IEEE模板中Section的编号是罗马数字,要是改投其他刊物的话可能得用阿拉伯数字,所以可以在导言部分做如下修改(放在导言区宏包调用之后): \ ...

  8. Python_Day_05 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuqe.Queue)

    Counter(计数器) 是一个字典的子类,存储形式同样为字典,其中存储的键为字典的元素,值为元素出现的次数,在使用之前我们需要先导入文件 import collections 初始化一个计数器 im ...

  9. 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuqe.Queue)

    Python_Day_05 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuq ...

  10. TypePerf.exe使用命令查找计数器

    TypePerf.exe是一个命令行工具,包括把Windows操作系统的性能计数器数据输出到命令窗口或写入到支持该功能的日志文件格式中. 通过以下两个参数获取计数器信息: -q [object] 列出 ...

随机推荐

  1. APP AutoTestCaseID

    public class AutoTestCaseID { ElementExist el = new ElementExist(); static AutoTestExcelFile ft = ne ...

  2. 往前端打smarty数据

    $data['hot_issue']=$hotIssue; var_dump($data);

  3. BZOJ 2594 【WC2006】 水管局长数据加强版

    题目链接:水管局长数据加强版 好久没写博客了…… 上次考试的时候写了一发LCT,但是写挂了……突然意识到我已经很久没有写过LCT了,于是今天找了道题来练练手. 首先,LCT这里不讲.这道题要求支持动态 ...

  4. c++ 判断容器是否为空

    #include <iostream> #include <vector> #include <string> using namespace std; int m ...

  5. 在多节点上运行分布式Intel Caffe

    一般有2种并行模式:数据并行(Data parallelism)和模型并行(model parallelism). 在模型并行化( model parallelism )方法里,分布式系统中的不同机器 ...

  6. flutter 安装详细教程

    Flutter 是 Google 用以帮助开发者在 iOS 和 Android 两个平台开发高质量原生 UI 的移动 SDK.Flutter 兼容现有的代码,免费且开源,在全球开发者中广泛被使用. 安 ...

  7. node的开发者环境设置丢失

    1.我看到的最简单的一种:evn 默认的值是  development var app = express(); if (app.get('env') === 'development') { req ...

  8. web sql 基本操作 - 增删改查

    不喜欢看md原文的 可以访问这个链接:http://note.youdao.com/noteshare?id=6a91e3dea7cdf5195bb0e851d9fcb5a5 # web sql 增删 ...

  9. 在JavaScript中进行文件处理,第五部分:Blobs

    译注:原文是<JavaScript高级程序设计>的作者Nicholas Zakas写的,本翻译纯属为自己学习而做,仅供参考.原文链接:这里 到目前为止,这个系列的帖子集中在和这些文件交互- ...

  10. C# 解决datatable写入文件内存溢出问题

    1.程序生成目标平台设为x64 2.文件写入后主动回收内存