如何在特定的设定时间使用VB创建通知弹出窗口。 [英] How do I create a notification popup using VB at a specific set time.

查看:172
本文介绍了如何在特定的设定时间使用VB创建通知弹出窗口。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用visual basic为我的软件类编写日历。我想实现一种方式,以便我的最终用户客户端可以选择一个日期让他们得到通知。因此,我们可以说他们将在几天内完成任务。弹出窗口出现,只是通知他们他们在日历中设置的即将到来的任务,以便他们知道日期。



我的问题是:我如何制作一个计时器,用于在特定时间运行通知(例如,距离截止日期时间48小时)。



以下是我的日历系统代码。我正在使用monthcalendar来选择日期,然后保存输入到记事本文档中的任何文本。



任何改进代码和创建通知的建议都是很有帮助。



我尝试了什么:



I am coding a Calendar in visual basic for my software class. I would like to implement a way so that my end user client can select a date for them to be notified. So lets say they have an assignment coming up in a few days. The popup appears and just notifies them of the upcoming task that they have set in the calendar so they are aware of the date.

My question is: How do i make a timer to run a notification at a specific time (48 hours away from the due date time for example).

Below is the code i have for my calendar system. I'm using monthcalendar to select a date and it is then saving any text entered into a notepad document.

Any suggestions in improving the code and creating the notification would be helpful.

What I have tried:

Imports System.IO

Public Class Form1

    Dim t As String
    Dim m As MsgBoxResult


    Private Sub MonthCalendar1_DateSelected(sender As Object, e As DateRangeEventArgs)

        t = MonthCalendar1.SelectionRange.Start.Month.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString

        Try
            If File.Exists(t & ".txt") = True Then
                MonthCalendar1.Enabled = False
                MonthCalendar1.Hide()
                TextBox1.Show()
                Button1.Enabled = True
                Button1.Show()
                Button2.Enabled = True
                Button2.Show()
                TextBox1.Text = File.ReadAllText(t & ".txt")
            Else
                m = MsgBox("Access this date?", MsgBoxStyle.YesNo)
                If m = MsgBoxResult.Yes Then
                    MonthCalendar1.Enabled = False
                    MonthCalendar1.Hide()
                    TextBox1.Enabled = True
                    TextBox1.Show()
                    TextBox1.Text = ""
                    Button1.Enabled = True
                    Button1.Show()
                    Button2.Enabled = True
                    Button2.Show()

                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Enabled = False
        TextBox1.Hide()
        Button1.Enabled = False
        Button1.Hide()
        Button2.Enabled = False
        Button2.Hide()
        MonthCalendar1.Enabled = True
        MonthCalendar1.Show()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            If TextBox1.Text = "" Then
                If File.Exists(t & ".txt") = True Then
                    File.Delete(t & ".txt")
                End If
            End If
            If TextBox1.Text.Length > 0 Then
                File.WriteAllText(t & ".txt", TextBox1.Text)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim m1 As MsgBoxResult
        t = MonthCalendar1.SelectionRange.Start.Month.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString

        If Date.Today = MonthCalendar1.TodayDate And File.Exists(t & ".txt") = True Then
            m1 = MsgBox("You have appointments set for today. Would you like to view them?", MsgBoxStyle.YesNo)
            If m1 = MsgBoxResult.Yes Then
                MonthCalendar1.Enabled = False
                MonthCalendar1.Hide()
                TextBox1.Enabled = True
                TextBox1.Show()
                Button1.Enabled = True
                Button1.Show()
                Button2.Enabled = True
                Button2.Show()
                TextBox1.Text = File.ReadAllText(t & ".txt")
            End If
        End If
    End Sub
End Class

推荐答案

向应用程序添加计时器,以便定期检查通知时间是否已到达。每次应用程序启动时都应启动计时器。
Add a timer to the application, so it can check regularly if the notification time has arrived. The timer should be started every time the application starts.


这篇关于如何在特定的设定时间使用VB创建通知弹出窗口。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆