如何使用vb.net刷新win表单?

如何使用vb.net刷新win表单?,vb.net,winforms,refresh,Vb.net,Winforms,Refresh,我正在为申请登记表工作,我想知道当用户打开登记表时,我需要检查当前日期是否为真,当用户试图更改系统日期时,他应该弹出消息。因此,我想每秒钟刷新一次表格,看看他是否更改了日期。 我该怎么做 这是我的密码: btnRegister.Enabled = False Dim oReg As Microsoft.Win32.RegistryKey oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", True

我正在为申请登记表工作,我想知道当用户打开登记表时,我需要检查当前日期是否为真,当用户试图更改系统日期时,他应该弹出消息。因此,我想每秒钟刷新一次表格,看看他是否更改了日期。 我该怎么做

这是我的密码:

 btnRegister.Enabled = False
    Dim oReg As Microsoft.Win32.RegistryKey
    oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", True)
    oReg = oReg.CreateSubKey(kstrRegSubKeyName)
    oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\" & kstrRegSubKeyName)
    Dim strOldDay As String = oReg.GetValue("UserSettings", "").ToString
    Dim strOldMonth As String = oReg.GetValue("operatingsystem", "").ToString
    Dim strOldYear As String = oReg.GetValue("GUID", "").ToString
    Dim strRegName As String = oReg.GetValue("USERID", "").ToString
    Dim strRegCode As String = oReg.GetValue("LOCALPATH", "").ToString
    Dim strCompID As String = oReg.GetValue("CompID", "").ToString
    Dim strTrialDone As String = oReg.GetValue("Enable", "").ToString
    oReg.Close()

    'If the keys should automatically be created, then create them.
    If strOldDay = "" Then
        CreateRegKeys(txtPassPhrase.Text)
    End If

    'If the keys are encrypted, decrypt them.
    'If EncryptKeys = True Then
    strOldDay = Decrypt(txtPassPhrase.Text, strOldDay)
    strOldMonth = Decrypt(txtPassPhrase.Text, strOldMonth)
    strOldYear = Decrypt(txtPassPhrase.Text, strOldYear)
    'End If

    'Define global variables.
    mintUsedTrialDays = DiffDate(strOldDay, strOldMonth, strOldYear)

    'Fill the progress bar
    lblApplicationStatus.Text = DisplayApplicationStatus(DiffDate(strOldDay, strOldMonth, strOldYear), mintTrialPeriod)

    'Disable the continue button if the trial is over
    If DiffDate(strOldDay, strOldMonth, strOldYear) > mintTrialPeriod Then
        'unregbutton.Enabled = False
        mblnInTrial = False
        btnRemind.Enabled = False
        oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", True)
        oReg = oReg.CreateSubKey(kstrRegSubKeyName)
        oReg.SetValue("Enable", "1")
        oReg.Close()
    End If




    If strOldMonth = "" Then

    Else

        Dim dtmOldDate As Date = New Date(Convert.ToInt32(strOldYear), Convert.ToInt32(strOldMonth), Convert.ToInt32(strOldDay))
        If Date.Compare(DateTime.Now, dtmOldDate) < 0 Then
            'lblApplicationStatus.Text = DisplayApplicationStatus(mintTrialPeriod, mintTrialPeriod)
            lblApplicationStatus.Text = "The system clock has been manually changed, and the application has been locked out to prevent unauthorized access!"
        End If
    End If


    'If the trial is done then disable the button
    If strTrialDone = "1" Then
        mblnInTrial = False
        btnRemind.Enabled = False
        lblApplicationStatus.Text = "The system clock has been manually changed, and the application has been locked out to prevent unauthorized access!"
    End If

    'See if the user is already registered, if so re-process the info and check if the computer is all okay.,
    If strRegName = "" Then
    Else
        Dim strRN As String = Decrypt(txtPassPhrase.Text, strRegName)
        Dim strRC As String = Decrypt(txtPassPhrase.Text, strRegCode)
        Dim UserName As String = strRegName
        UserName = UserName.Remove(16, (UserName.Length - 16))
        If UserName = Decrypt(txtPassPhrase.Text, strRegCode) Then
            If Encrypt(txtPassPhrase.Text, cHardware.GetMotherBoardID.Trim.ToString) = strCompID Then
                mblnInTrial = False
                mblnFullVersion = True
                strRC = strRC.Insert(4, "-")
                strRC = strRC.Insert(8, "-")
                strRC = strRC.Insert(12, "-") 'Add dashes to make it look cool
                lblApplicationStatus.Text = "Licensed version to " + strRN + " with the key " + strRC
                txtVKClientName.Enabled = False
                txtKeyToValidate.Enabled = False
                txtVKClientName.Text = strRN
                txtKeyToValidate.Text = strRC
                btnRemind.Text = "Registered"
                frmMain.Text = "Aquamark v1.2(Registered)"
                btnRegister.Hide()
                Me.Close()
                frmMain.Show()
                oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", True)
                oReg = oReg.CreateSubKey(kstrRegSubKeyName)
                oReg.SetValue("Enable", "")
                oReg.Close()
            End If
        End If
    End If
btnRegister.Enabled=False
将oReg设置为Microsoft.Win32.RegistryKey
oReg=Microsoft.Win32.Registry.CurrentUser.OpenSubKey(“软件”,真)
oReg=oReg.CreateSubKey(kstrRegSubKeyName)
oReg=Microsoft.Win32.Registry.CurrentUser.OpenSubKey(“软件\\”&kstrRegSubKeyName)
Dim strOldDay As String=oReg.GetValue(“UserSettings”,下称“).ToString
Dim strOldMonth As String=oReg.GetValue(“operatingsystem”,“操作系统”)。ToString
Dim strOldYear As String=oReg.GetValue(“GUID”,”).ToString
Dim strengame As String=oReg.GetValue(“USERID”,即“”).ToString
Dim STREGCODE As String=oReg.GetValue(“LOCALPATH”,”).ToString
Dim strCompID As String=oReg.GetValue(“CompID”,”).ToString
Dim strTrialDone As String=oReg.GetValue(“启用”).ToString
oReg.Close()
'如果应自动创建密钥,则创建它们。
如果strOldDay=“”,则
CreateRegKeys(txtPassPhrase.Text)
如果结束
'如果密钥已加密,请解密它们。
'如果EncryptKeys=True,则
strOldDay=解密(txtPassPhrase.Text,strOldDay)
strOldMonth=解密(txtPassPhrase.Text,strOldMonth)
strOldYear=解密(txtPassPhrase.Text,strOldYear)
"完"
'定义全局变量。
MintUsedTrialdDays=DiffDate(strOldDay、strOldMonth、strOldYear)
'填充进度栏
lblApplicationStatus.Text=显示应用程序状态(DiffDate(strOldDay、strOldMonth、strOldYear)、mintTrialPeriod)
'如果试用结束,请禁用“继续”按钮
如果DiffDate(strOldDay、strOldMonth、strOldYear)>mintTrialPeriod,则
'unregbutton.Enabled=False
mblnInTrial=False
btnRemind.Enabled=False
oReg=Microsoft.Win32.Registry.CurrentUser.OpenSubKey(“软件”,真)
oReg=oReg.CreateSubKey(kstrRegSubKeyName)
oReg.SetValue(“启用”、“1”)
oReg.Close()
如果结束
如果strOldMonth=“”,则
其他的
Dim dtmOldDate As Date=新日期(Convert.ToInt32(strOldYear)、Convert.ToInt32(strOldMonth)、Convert.ToInt32(strOldDay))
如果Date.Compare(DateTime.Now,dtmOldDate)<0,则
'lblApplicationStatus.Text=DisplayApplicationStatus(mintTrialPeriod,mintTrialPeriod)
lblApplicationStatus.Text=“系统时钟已手动更改,应用程序已锁定以防止未经授权的访问!”
如果结束
如果结束
'如果试验完成,则禁用按钮
如果strTrialDone=“1”,则
mblnInTrial=False
btnRemind.Enabled=False
lblApplicationStatus.Text=“系统时钟已手动更改,应用程序已锁定以防止未经授权的访问!”
如果结束
'查看用户是否已注册,如果已注册,请重新处理信息并检查计算机是否正常。'。,
如果strengame=“”,则
其他的
Dim strRN As String=解密(txtPassPhrase.Text,strgname)
Dim strRC As String=解密(txtPassPhrase.Text,strRegCode)
Dim用户名为String=strengame
UserName=UserName.Remove(16,(UserName.Length-16))
如果UserName=Decrypt(txtPassPhrase.Text,stregcode),则
如果Encrypt(txtPassPhrase.Text,cHardware.GetMotherBoardID.Trim.ToString)=strCompID,则
mblnInTrial=False
mblnFullVersion=True
strRC=strRC。插入(4,“-”)
strRC=strRC。插入(8,“-”)
strRC=strRC.Insert(12,“-”)添加破折号使其看起来很酷
lblApplicationStatus.Text=“使用“+strRC”键将许可版本设置为“+strRN+”
txtVKClientName.Enabled=False
txtKeyToValidate.Enabled=False
txtVKClientName.Text=strRN
txtKeyToValidate.Text=strRC
btnRemind.Text=“已注册”
frmMain.Text=“Aquamark v1.2(已注册)”
btnRegister.Hide()
我
frmMain.Show()
oReg=Microsoft.Win32.Registry.CurrentUser.OpenSubKey(“软件”,真)
oReg=oReg.CreateSubKey(kstrRegSubKeyName)
oReg.SetValue(“启用”、“”)
oReg.Close()
如果结束
如果结束
如果结束

您可以订阅,当用户更改系统时钟上的时间时将触发。不要忘记在表单关闭时分离事件处理程序,因为这是一个静态事件

您可以将日期存储在字段中,并在系统时间更改时将新日期与之进行比较,或者在事件发生时仅禁用应用程序。

不,您不必“
每隔一秒刷新表单并查找他是否更改了日期。我该如何操作”
,解决方案要简单得多

数据更改时,windows将向所有应用程序发送消息。改为收听该消息,并在数据更改时执行您希望执行的操作:

//很抱歉,我不懂VB,但代码很简单,你应该毫无问题地转换它

private DateTime _lastSystemClockChanged = DateTime.MinValue;

protected override void WndProc(ref Message m)
{
    switch (m.Msg)
    {
        case 0x1E://the time is changed. 
            //to avoid receiving duplicate notification about time changed
            if (_lastSystemClockChanged.AddSeconds(1) < DateTime.Now ||
                _lastSystemClockChanged > DateTime.Now)
            {
                _lastSystemClockChanged = DateTime.Now;
                //do what ever you want to do when time changed. note you should 
                //not call a methods that will block here because of you will block 
                //this message from arriving to other applications then
            }
            break;
    }
    base.WndProc(ref m);
}
private DateTime\u lastSystemClockChanged=DateTime.MinValue;
受保护的覆盖无效WndProc(参考消息m)
{
开关(m.Msg)
{
案例0x1E://时间已更改。
//避免收到有关时间更改的重复通知
如果(_lastSystemClockChanged.AddSeconds(1)DateTime.Now)
{
_lastSystemClockChanged=DateTime.Now;
//做你想做的事