如何根据值启用/禁用VB.Net中的按钮?

时间:2012-10-10 12:54:42

标签: c# .net vb.net visual-studio

我需要在dzien=0时禁用我的按钮,并在dzien >0时启用。

当我启动应用程序时,如果日期为0或102938129038无关紧要,则按钮仍处于禁用状态。我的代码出了什么问题?

Imports System.IO.IsolatedStorage
Partial Public Class Page1
Inherits PhoneApplicationPage
Private dzien As Integer
Public Sub New()
    InitializeComponent()
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
    IsolatedStorageSettings.ApplicationSettings("dzien") = dzien
    Try
        dzien = CInt(IsolatedStorageSettings.ApplicationSettings("dzien"))
    Catch ex As KeyNotFoundException
        dzien = 0
    End Try
    If dzien = 0 Then
        dzien = dzien + 1
    End If
    NavigationService.Navigate(New Uri("/2.xaml", UriKind.Relative))
End Sub
Private Sub Class_1_loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
    If dzien = 0 Then
        Button2.IsEnabled = False
    Else
        Button2.IsEnabled = True
    End If

End Sub
Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click

    dzien = dzien + 1

    NavigationService.Navigate(New Uri("/2.xaml", UriKind.Relative))
End Sub
End Class

我不确定是否

If dzien = 0 Then
    dzien = dzien + 1
End If

运作良好 和

dzien = dzien + 1

2 个答案:

答案 0 :(得分:3)

Private Sub Class_1_loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
If dzien = 0 Then
   Button2.Enabled = False
Else 
   Button2.Enabled = True
End Sub

答案 1 :(得分:0)

我不确定,但如果.ENABLED.ISENABLED不相同,我认为这就是问题......