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. MSSQL 重建索引(在线重建、控制最大处理器数 、MAXDOP )

    一.什么情况下需要重建索引 1.碎片过多(参考值:>20%) 索引碎片如何产生,请移步至< T-SQL查询高级—SQL Server索引中的碎片和填充因子> 2.填充度过低(参考值: ...

  2. python 判断列表字符串元素首尾字符是否相同

    def match_words(words): ctr = for word in words: and word[] == word[-]: ctr += return ctr print(matc ...

  3. mysql获取随机数据的方法

    order by rand() 数据多了极慢,随机性非常好,适合非常小数据量的情况. 复制代码 代码如下: SELECT * FROM table_name AS r1 JOIN (SELECT (R ...

  4. Android 自定义注解(Annotation)

    现在市面上很多框架都有使用到注解,比如butterknife库.EventBus库.Retrofit库等等.也是一直好奇他们都是怎么做到的,注解的工作原理是啥.咱们能不能自己去实现一个简单的注解呢. ...

  5. Android之shape与selector实现圆角

    shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...

  6. Java网络编程学习A轮_06_NIO入门

    参考资料: 老外写的教程,很适合入门:http://tutorials.jenkov.com/java-nio/index.html 上面教程的译文:http://ifeve.com/overview ...

  7. $state和$rootScope.$on($stateChangeStart)

    这两者的区别:请看博客:http://stackoverflow.com/questions/32680292/angularjs-state-and-rootscope-onstatechanges ...

  8. Java Spring-AspectJ

    2017-11-10 21:25:02 Spring的AspectJ的AOPAspectJ 是一个面向切面的框架,它扩展了 Java 语言. AspectJ 定义了 AOP 语法所以它有一个专门的编译 ...

  9. 递归--练习4--noi666放苹果

    递归--练习4--noi666放苹果 一.心得 写出状态后勇敢假设 二.题目 666:放苹果 总时间限制:  1000ms 内存限制:  65536kB 描述 把M个同样的苹果放在N个同样的盘子里,允 ...

  10. EK算法复杂度分析

    引理: EK算法每次增广使所有顶点$v\in V-\{s,t\}$到$s$的最短距离$d[v]$增大. 采用反证法, 假设存在一个点$v\in V-\{s,t\}$, 使得$d'[v]< d[v ...