NEWS

[C#] Thiết kế đồng hồ kỹ thuật số có hiệu ứng scrolling winform

[C#] Thiết kế đồng hồ kỹ thuật số có hiệu ứng scrolling winform
Đăng bởi: Thảo Meo - Lượt xem: 5330 15:31:46, 12/10/2021PHẦN MỀM

Xin chào các bạn, bài viết hôm nay mình sẻ hướng dẫn các bạn thiết kế đồng hồ kỹ thuật số trên lập trình c#, winform có hiệu ứng scrolling.

[C#] Digital Clock with effect scrolling

Để thiết kế đồng hồ kỹ thuật số trên winform, thì đơn giản, các bạn chỉ cần gọi hàm DateTime.Now() và ở sự kiện event Tick của Timer.

Và set interval = 1000 (1 giây) trong timer là xong.

Các bạn có thể thiết kế lại mẫu số theo nhu cầu yêu thích của các bạn, bài viết này mình sử dụng mẫu hình số như bên dưới:

n01

Ở bài này mình thiết kế ứng dụng nó như một Gadget đồng hồ trên Desktop:

digittal_csharp

Video demo ứng dụng Digital Clock C#:

Ở ứng dụng này mình khi chạy đầu tiên, mình sẻ cài đặt ứng dụng hiển thị mặc định ở góc phải bên trên màn hình Desktop.

Full source code Digital Clock C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DigitalClock
{
    public partial class Form1 : Form
    {      
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            this.StartPosition = FormStartPosition.Manual;
            foreach (var scrn in Screen.AllScreens)
            {
                if (scrn.Bounds.Contains(this.Location))
                {
                    this.Location = new Point(scrn.Bounds.Right - this.Width, scrn.Bounds.Top);
                    return;
                }
            }          
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            SendToBack();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            var hour = DateTime.Now.Hour; 
            var minute = DateTime.Now.Minute;
            var second = DateTime.Now.Second;
            if(second % 2 == 0)
            {
                lbl_splash.Visible = true;
            }
            else
            {
                lbl_splash.Visible = false;
            }
            txt_hour.Value = hour;
            txt_minute.Value = minute;
            txt_second.Value = second;

        }

        private void label6_Click(object sender, EventArgs e)
        {
            Process.Start("https://laptrinhvb.net");
        }
    }
}

Thanks for watching!

Pass Unrar: laptrinhvb.net

DOWNLOAD SOURCE

Tags: digital clock c#effect digital clock c#gadget clock c#

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Thiết kế đồng hồ kỹ thuật số có hiệu ứng scrolling winform
Đăng bởi: Thảo Meo - Lượt xem: 5330 15:31:46, 12/10/2021PHẦN MỀM