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. MyBatis的简单入门学习

    一个新知识开始是最难学的.(万事开头难) MyBatis大体分三层,接口层,数据处理层,基础支撑层. 其中接口层不是java中的那个interface,而是框架和程序员之间的对接.一个API,程序员可 ...

  2. springboot p6spy 打印完整sql

    调试时打印出sql的需求,太正常不过了,mybatis也提供了这样的功能: mybatis: configuration: log-impl: org.apache.ibatis.logging.st ...

  3. install_github安装错误解决方法

    install.packages('devtools')library(devtools)install_github('hdng/clonevol') Installation failed: Ti ...

  4. 一些自己常用的cdn

    1.vue <script src="http://cdn.bootcss.com/vue/1.0.28-csp/vue.js"></script> < ...

  5. subllime的插件使用

    1.emmet快速使用的方法. html:xt 然后按下tab快速的生成一个html文档. 生成10个div----- div*10 div->ul->li->a->img 写 ...

  6. JPA使用指南 javax.persistence的注解配置

    @SuppressWarnings("serial") @Entity @Table(name="T_X") public class X implements ...

  7. php---------正则判断字符串中是否由汉字 数字 英文字母组成

    开发中常常用到正则表达式,分享两个常用的正则表达式,php检查字符串是否由汉字,数字,英文字母,下划线组成, 注意这里只是针对utf-8字符集的字符串检查. 数字 汉字 英文字母: if (!preg ...

  8. oracle性能诊断艺术-执行计划

    --case1 --case2 --case3 --case4 --case5 --case6 --case7 --case8 --case9 --case10 --case12 SQL> AL ...

  9. OAF TABLE中第一列添加事件不生效

    我遇到一个比较诡异的现象 在TABLE中,我在TABLE的第一列添加了一个MessageCheckBox,并为其设置全局刷新的FireAction事件selection, 但是点击勾选框按钮之后,事件 ...

  10. 007——php字符串中的处理函数(六)

    <?php /** * 一.addslashes() 在预定义字符串前添加反斜杠 * * stripslashes() 把转义字符串前的反斜杠删除 * get_magic_quotes_gpc ...