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. UVa 10294 项链和手镯(polya)

    https://vjudge.net/problem/UVA-10294 题意: 手镯可以翻转,但项链不可以.输入n和t,输出用t种颜色的n颗珠子能制作成的项链和手镯的个数. 思路: 经典等价类计数问 ...

  2. 如何优雅地发布Hexo博客

    前言 就目前而言,我所知道的发布Hexo的博客有如下几种: 1.原始方式,也就是在服务器上编写md文件,然后利用hexo g来生成,详见:hexo从零开始到搭建完整: 2.利用github+hook来 ...

  3. DWZ 框架详解

    这是一个智障的框架,能别用就别用.

  4. m_Orchestrate learning system---网站的语言选择功能(中文英文)

    m_Orchestrate learning system---网站的语言选择功能(中文英文) 一.总结 一句话总结:有两种方法,一是session+js端代码,而是session+php端代码. 推 ...

  5. Python str 与 bytes 类型 之间的转换

    bytes:字节数组,通常用它可以描述 “一个字符串”,只不过该字符串是  “bytes类型”,所以容易与str类型混淆,他们二者之间的转换: https://blog.csdn.net/lanchu ...

  6. 获取iframe(angular 动态页面)高度

    问题比较特殊,google了好久才得到启示 开发的angular页面,需要嵌入到客户的web页中,以iframe方式.由于iframe的高度需要指定,而angular动态生成机制导致页面高度会随时变化 ...

  7. bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积

    在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...

  8. IE6开发调试插件:IE Developer Toolbar

    下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=18359 1.下载后点击安装 2.安装后重启IE6

  9. 从0开始springboot

    http://412887952-qq-com.iteye.com/blog/2291500

  10. 017PHP基础知识——流程控制语句(五)

    <?php /** * break;退出循环: * 语法结构:break int;可以指定跳过几级循环: * while do_while for foreach switch */ /*$i= ...