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. notepad++下载32位,安装插件管理

    下载32位地址: https://notepad-plus-plus.org/download/v7.6.4.html 下载插件: 链接: https://pan.baidu.com/s/1tRSo4 ...

  2. 解决Tomcat端口被占用 及 启用失败等其它错误整理册

    使用管理员模式启动命令行工具. netstat -ano|findstr 获取了pid号 taskkill /pid /f 其中6428为pid号,可能有不同. -------- 有时遇到其它问题可以 ...

  3. LA 2963 超级传输(扫描)

    https://vjudge.net/problem/UVALive-2963 题意:需要在n个星球上各装一个广播装置,作用范围均为R.每个星球广播A类节目或者B类节目.a表示星球i收听到的和自己广播 ...

  4. BZOJ 3123 【SDOI2013】 森林

    题目链接:森林 这道题想法很显然.既然只有加边而没有删边,那么每次启发式合并就可以了.查询路径\(k\)小似乎需要主席树,那么把主席树和倍增表一起暴力重构就好了. 然后发现这样的空间复杂度是\(O(n ...

  5. Codeforces Round #396 (Div. 2) A,B,C,D,E

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  6. Chain of Responsibility(责任链)

    意图: 使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止. 适用性: 有多个的对象可以处理一个请求,哪个对 ...

  7. Spring IOC容器的初始化流程

    IOC初始化流程 Resource定位:指对BeanDefinition的资源定位过程.Bean 可能定义在XML中,或者是一个注解,或者是其他形式.这些都被用Resource来定位, 读取Resou ...

  8. JDK_源码

    1.http://hg.openjdk.java.net/ (ZC:这个貌似像官网的样子,不知道 到底是不是...) 1.1.jdk8u_jdk8u_jdk_ 5b86f66575b7 _src_.h ...

  9. bzoj1179: [Apio2009]Atm scc缩点+dag上dp

    先把强连通缩点,然后变成了dag,dp求终点是酒吧的最长路即可, /************************************************************** Pro ...

  10. 使用POI导入小数变成浮点数异常

    例如   我在Excel中的数据为17.2, 导入到表中就变成了17.1999999或者17.20000001 原因是我用double接收了17.2,然后直接用了String去转换,精度就丢失了. 代 ...