专栏首页VB小源码VB.NET 高考倒计时LED屏显效果

VB.NET 高考倒计时LED屏显效果

倒计时原理:

  用DateDiff函数计算出两个时间的差值,然后通过timer控件,每秒钟获取一次时间差值,然后显示出来!

LED效果原理:

  用Graphics绘制,实现文字和图片的遮罩(请看第二篇文章)

倒计时源码
Public Class Count_down
    Dim L As Long, T As Long, X As Long, Y As Long
    ''' <summary>
    ''' 构造时差
    ''' </summary>
    Structure Date_time
        Dim SC_D As Long ''时差天
        Dim SC_H As Long ''时差时
        Dim SC_M As Long ''时差分
        Dim SC_S As Long ''时差秒
    End Structure
    ''' <summary>
    ''' 获取时差
    ''' </summary>
    ''' <param name="D"></param>
    ''' <returns></returns>
    Function GET_SC(ByVal D As Date) As Date_time  ''取时差
        If IsDate(D) Then
            Dim SD As New Date_time With {
                .SC_D = DateDiff("d", Now, D), '取相差天数
                .SC_H = DateDiff("h", Now, D) Mod 24, '取相差时数
                .SC_M = DateDiff("n", Now, D) Mod 60, '取相差分数
                .SC_S = DateDiff("s", Now, D) Mod 60 '取相差秒数
            }
            Return SD
        Else
            MsgBox($"请输入标准时间格式", MsgBoxStyle.Critical, "时间错误")
        End If
    End Function
    ''' <summary>
    ''' 计时器
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim S As Date_time = GET_SC("2020/06/07 8:00:00")
        Timer1.Interval = 1000
        If S.SC_D = 0 And S.SC_H = 0 And S.SC_M = 0 And S.SC_S = 0 Then
            MASK_IMG("2020年高考开始啦!", $"同学们准备好了吗?")
            Timer1.Enabled = False
            Exit Sub
        Else
            MASK_IMG("距离 2020年 高考", $"还剩 {S.SC_D} 天 {S.SC_H} 小时 {S.SC_M} 分 {S.SC_S}秒")
        End If
    End Sub
    ''' <summary>
    ''' LED
    ''' </summary>
    ''' <param name="s"></param>
    ''' <param name="STR"></param>
    Private Sub MASK_IMG(ByVal s As String, ByVal STR As String)
        Dim B As New Bitmap(Width, Height)
        Using G As Graphics = Graphics.FromImage(B)
            G.Clip = New Region(New Rectangle(0, 0, Width, Height))
            G.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed
            G.DrawString("微信公众号关注:VB小源码", New Font("黑体", Led1.Width * 0.011), Brushes.Red, New Point(Led1.Width * 0.25, Led1.Height * 0.42))
            G.DrawString(s, New Font("微软雅黑", Led1.Width * 0.019), Brushes.Yellow, New Point(Led1.Width * 0.01, Led1.Height * 0.05))
            G.DrawString(STR, New Font("宋体", Led1.Width * 0.018), Brushes.LimeGreen, New Point(Led1.Width * 0.06, Led1.Height * 0.2))
            G.DrawString("决战高考,改变命运。屡挫屡战,笑傲群雄。", New Font("仿宋", Led1.Width * 0.015), Brushes.Yellow, New Point(Led1.Width * 0.01, Led1.Height * 0.32))
        End Using
        Led1.INPUT_IMG = B
    End Sub

    Private Sub Count_down_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim S As Date_time = GET_SC("2020/06/07 8:00:00")
        If (S.SC_D < 0 Or S.SC_H < 0 Or S.SC_M < 0 Or S.SC_S < 0) = True Then
            Exit Sub
        End If
        Timer1.Interval = 1
        Timer1.Enabled = True
    End Sub

无边框窗体移动部分

    Private Sub Count_down_Closed(sender As Object, e As EventArgs) Handles Me.Closed
        End
    End Sub

    Private Sub Led1_MouseDown(sender As Object, e As MouseEventArgs) Handles Led1.MouseDown
        L = Led1.Left
        T = Led1.Top
        X = e.X
        Y = e.Y
    End Sub


    Private Sub Led1_MouseMove(sender As Object, e As MouseEventArgs) Handles Led1.MouseMove
        If Led1.Capture = True Then
            Top = e.Y + T - Y
            Left = e.X + L - X
            L = Left
            T = Top
        End If
    End Sub

    Private Sub Led1_KeyDown(sender As Object, e As KeyEventArgs) Handles Led1.KeyDown
        If e.KeyCode = Keys.Escape Then
            If MsgBox("是否要退出倒计时?", MsgBoxStyle.YesNo, "退出") = MsgBoxResult.Yes Then End
        End If
    End Sub


无边框窗体放大部分

    Private Sub Led1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles Led1.MouseDoubleClick
        If WindowState = FormWindowState.Normal Then
            Led1.INPUT_IMG = New Bitmap(1, 1)
            Timer1.Interval = 1
            WindowState = FormWindowState.Maximized
        Else
            WindowState = FormWindowState.Normal
        End If
    End Sub


End Class

实例下载:

https://www.lanzous.com/i72udmj

今天教程到此结束啦!

本文分享自微信公众号 - VB小源码(vb_xym),作者:VB小源码

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

原始发表时间:2019-10-30

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • #安卓开发# B4A示例20200217:《抖印无踪》

    这是一款集,权限获取,粘贴板应用,菜单应用,网页跳转,文件下载,创建目录,json解析,网页请求,控件简单使用 ,于一体的教程示例!

    巴西_prince
  • VBA批量获取文件夹和文件名

    With Application.FileDialog(msoFileDialogFolderPicker)

    巴西_prince
  • VBA 发票数据解析

    巴西_prince
  • 常见的50道数据库面试题

    前言:2021年的第一篇公众号,希望自己在学到知识的同时也能分享给大家,一起进步!!

    小雯子打豆豆
  • Linux基础(day 34)

    10.15 iptables filter表案例 iptables常用知识回顾点 iptables -I/-A/-D 后紧跟 链 ,可以是INPUT,OUTPU...

    运维小白
  • python源码阅读笔记之几个值得注意的点

    哒呵呵
  • LintCode 左填充题目代码

    desperate633
  • Markdown的安装以及简单使用教程

    st= start: Start io= inputoutput: verification op= operation: Your Operation ...

    緣來
  • 好久没更新的我来一发fusion360的小白教程

    整个2月都沉浸毕设的纠结之中在过年的快乐之中,也没有什么新的想法,于是又开始炒冷饭,等这段时间有眉目了分享一波毕设hhh

    UDM Lab
  • 数据结构C#版笔记--啥夫曼树(Huffman Tree)与啥夫曼编码(Huffman Encoding)

    哈夫曼树Huffman tree 又称最优完全二叉树,切入正题之前,先看几个定义 1、路径 Path 简单点讲,路径就是从一个指定节点走到另一个指定节点所经过的...

    菩提树下的杨过

扫码关注云+社区

领取腾讯云代金券