2011-07-28 8 views
0

私はアプリケーション登録フォームのために働いていますが、ユーザーが登録フォームを開いたときに知りたいのですが、現在の日付が真であるかどうかをチェックする必要があり、ユーザーがシステム日付を変更しようとすると、だから私は1秒ごとにフォームをリフレッシュして、彼が日付を変更したかどうかを確認したいと思います。 どうすればいいですか?vb.netを使用して勝利フォームをリフレッシュするには?

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 

答えて

0

NO、あなたが「refresh the form for every second and find whether he has changed the date or not. How do I do that」持っていない、ソリューションは、データが変更されたときに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); 
} 
せずにそれを変換する必要があり

// C#申し訳ありません

+0

ありがとうございましたjalalあなたは私にとって非常にシンプルにしましたが、たとえそれがC#でもVB変換器で管理することはできます。 –

+0

@volety:あなたも大歓迎です;) –

0

あなたは、ユーザーがシステムクロックの時刻を変更するときに発生するSystemEvents.TimeChanged event、に加入することができます:

は、ここに私のコードです。これが静的なイベントであるため、フォームが閉じたときにイベントハンドラを切り離すことを忘れないでください。

フィールドに日付を保存し、システム時刻が変更されたときに新しい日付と比較したり、イベントが発生したときにアプリを無効にしたりすることができます。

+0

あなたの返事をありがとう。 –

+0

あなたの助けをありがとう、上記の解決策のために働いた。 –

関連する問題