Share vb.net timer 5 minutes

honglan139

New member
### Cách tạo bộ đếm thời gian 5 phút trong vb.net

**Tổng quan**

Hướng dẫn này sẽ chỉ cho bạn cách tạo bộ đếm thời gian 5 phút trong vb.net.Chúng tôi sẽ sử dụng lớp `system.timers.timer` để tạo bộ hẹn giờ sẽ bắn cứ sau 5 phút.Chúng tôi cũng sẽ chỉ cho bạn cách sử dụng lớp `Timer` để hiển thị hộp thông báo khi hết thời gian.

** Bước 1: Tạo một dự án mới **

Để tạo một dự án mới, hãy mở Visual Studio và chọn tệp **> mới> Dự án **.Trong hộp thoại ** New Project **, chọn ** Visual Basic> Windows Forms Ứng dụng ** và nhấp vào ** OK **.

** Bước 2: Thêm điều khiển hẹn giờ vào biểu mẫu **

Trong hộp công cụ ** **, bấm đúp vào điều khiển ** bộ đếm thời gian ** để thêm nó vào biểu mẫu.

** Bước 3: Đặt khoảng thời gian của bộ hẹn giờ **

Bấm đúp vào điều khiển bộ đếm thời gian để mở cửa sổ ** Timer ** Thuộc tính.Trong thuộc tính ** khoảng **, nhập `5000`.Điều này sẽ đặt bộ hẹn giờ để bắn cứ sau 5000 mili giây, tương đương với 5 phút.

** Bước 4: Thêm một trình xử lý cho sự kiện đã qua của bộ đếm thời gian **

Trong cửa sổ ** Timer ** Thuộc tính, nhấp vào nút ** sự kiện ** và chọn ** Đã qua **.Điều này sẽ tạo ra một trình xử lý cho sự kiện `abapsed` của bộ đếm thời gian.

** Bước 5: Viết mã cho sự kiện đã qua của bộ đếm thời gian **

Trong Trình chỉnh sửa mã, thêm mã sau vào trình xử lý sự kiện `ELAPSEDIED:

`` `VBNet
TIMER phụ riêng1_elapsed (người gửi dưới dạng đối tượng, e như System.eventargs) xử lý Timer1.Enapsed
'Hiển thị hộp thông báo khi hết thời gian.
MessageBox.Show ("Bộ đếm thời gian đã hết hạn.")
Kết thúc phụ
`` `

** Bước 6: Chạy dự án **

Nhấn ** F5 ** để chạy dự án.Bộ hẹn giờ sẽ bắt đầu và sẽ bắn cứ sau 5 phút.Khi bộ hẹn giờ hết hạn, một hộp thông báo sẽ được hiển thị.

**Phần kết luận**

Trong hướng dẫn này, bạn đã học cách tạo bộ đếm thời gian 5 phút trong vb.net.Bạn đã sử dụng lớp `System.timers.timer` để tạo bộ hẹn giờ sẽ bắn cứ sau 5 phút.Bạn cũng đã học cách sử dụng lớp `Timer` để hiển thị hộp thông báo khi hết thời gian.

### hashtags

* #vb.net
* #Timer
* #5 phút hẹn giờ
* #Visual Studio
* #Windows Forms
=======================================
### How to Create a 5-Minute Timer in VB.NET

**Overview**

This tutorial will show you how to create a 5-minute timer in VB.NET. We'll use the `System.Timers.Timer` class to create a timer that will fire every 5 minutes. We'll also show you how to use the `Timer` class to display a message box when the timer expires.

**Step 1: Create a New Project**

To create a new project, open Visual Studio and select **File > New > Project**. In the **New Project** dialog box, select **Visual Basic > Windows Forms Application** and click **OK**.

**Step 2: Add a Timer Control to the Form**

In the **Toolbox**, double-click the **Timer** control to add it to the form.

**Step 3: Set the Timer's Interval**

Double-click the timer control to open the **Timer** Properties window. In the **Interval** property, enter `5000`. This will set the timer to fire every 5000 milliseconds, which is equivalent to 5 minutes.

**Step 4: Add a Handler for the Timer's Elapsed Event**

In the **Timer** Properties window, click the **Event** button and select **Elapsed**. This will create a handler for the timer's `Elapsed` event.

**Step 5: Write the Code for the Timer's Elapsed Event**

In the code editor, add the following code to the `Elapsed` event handler:

```vbnet
Private Sub Timer1_Elapsed(sender As Object, e As System.EventArgs) Handles Timer1.Elapsed
' Display a message box when the timer expires.
MessageBox.Show("The timer has expired.")
End Sub
```

**Step 6: Run the Project**

Press **F5** to run the project. The timer will start and will fire every 5 minutes. When the timer expires, a message box will be displayed.

**Conclusion**

In this tutorial, you learned how to create a 5-minute timer in VB.NET. You used the `System.Timers.Timer` class to create a timer that would fire every 5 minutes. You also learned how to use the `Timer` class to display a message box when the timer expired.

### Hashtags

* #vb.net
* #Timer
* #5-minute timer
* #Visual studio
* #Windows forms
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top