在VB.net怎么实现标签初始值为0,按F1就加1,按F2就减1啊。

解决方案 »

  1.   


    Dim Num As LongPrivate Sub Form_Load()
    me.keypreview=true
    End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF1 Then
        Num = Num + 1
        Label1.Caption = Num
    ElseIf KeyCode = vbKeyF2 Then
        Num = Num - 1
        Label1.Caption = Num
    End If
    End Sub
      

  2.   

    哈,他那代码是VB的,不是vbnet的,当然不对了
    只要看Form_KeyDown(KeyCode As Integer, Shift As Integer)就可以判断出来了嘛不过实质都是一样的,用form的keydown事件来完成Public Class Form1    Public i As Integer    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            If e.KeyCode = Keys.F1 Then
                i = i + 1
            End If
            If e.KeyCode = Keys.F2 Then
                i = i + 2
            End If
            Me.Label1.Text = i    End Sub    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            i = 0
            Me.Label1.Text = i
        End Sub   
    End Class