2014-04-08 3 views
0

프로그램을 실행하는 동안 버튼을 다른 버튼으로 변경하는 방법이 있습니까? 즉, 사용자가 '디스플레이'버튼을 클릭하면 결과가 계산되고 '디스플레이'가 "재시작?" 사용자가 클릭하면 프로그램이 다시 시작됩니까? 내가 btnRestart에 btnDisplay을 변경하려면 : 텍스트가 디스플레이 업데이트 인 경우 그 다음 추가 재시작 경우는 .text 특성에 따라 선택하는 경우를 온 클릭 핸들러에서계산 버튼을 클릭하여 다시 시작 버튼을 변경

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click 
    ' displays a student's grade 

    Double.TryParse(txtEarned.Text, dblEarned) 

    For Each minimum As Double In dblMinimumPoints 
     If dblEarned >= minimum Then 
      lblGrade.Text = strGrade(gradeIndex) 
      gradeIndex += 1 
     End If 
    Next 

    txtEarned.ReadOnly = False 
    btnDisplay.Enabled = False 

End Sub 

답변

1

을 추가, 그것은 다시 시작에 재시작 할 때 스크립트를 시작할 위치로 이동합니다.

편집, 아마 고토보다 더 나은 솔루션을 함수로 codetorun을 추가 한 아래 :이 작업을 수행하는 여러 가지 방법이 있습니다 가정

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click 

     Select Case btnDisplay.Text 
      Case "Submit" 
       codeiwanttorun() 
       btnDisplay.Text = "Restart" 
      Case "Restart" 
       codeiwanttorun() 

     End Select 

    End Sub 


    Private Function codeiwanttorun() 
     Double.TryParse(txtEarned.Text, dblEarned) 

     For Each minimum As Double In dblMinimumPoints 
      If dblEarned >= minimum Then 
       lblGrade.Text = strGrade(gradeIndex) 
       gradeIndex += 1 
      End If 
     Next 
    End Function 
+0

당신이 나에게 예를 제공 할 수 있습니다 (또한이 잘못하더라도, 당신은 확신 할 수 있도록 Visible 라인이 실행됩니다. 이러한 이벤트에서 처리 일부 Try...Finally 오류를 추가 할 수 있습니다)? 내가 선택한 사건에 익숙하지 않다. – 0000

+0

회신 지연에 사과드립니다. 내 게시물을 업데이트하여 도움이되는지 확인하십시오. – dave

+0

문제가없는 친구, 일부 사례를 자세히 살펴보면 매우 유용합니다. – 0000

2

. 하나는 양식 디자이너에서 서로 위에 놓이는 두 개의 단추, Text이있는 btnDisplaybtnRestart입니다. 클릭 할 때 표시되는 것을 번갈아 표시합니다.

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click 
' displays a student's grade 

Double.TryParse(txtEarned.Text, dblEarned) 

For Each minimum As Double In dblMinimumPoints 
    If dblEarned >= minimum Then 
     lblGrade.Text = strGrade(gradeIndex) 
     gradeIndex += 1 
    End If 
Next 

txtEarned.ReadOnly = False 
btnDisplay.Visible = False 
btnReset.Visible = True 

End Sub 

나는 btnRestart는 "프로그램을 다시 시작"것이라고 말함으로써 당신이 무슨 뜻인지 잘 모르겠지만, 아마도 그것의 클릭 이벤트에서 당신은 마찬가지로 그것을 숨길 것이 다시 볼 수 btnDisplay을합니다.

관련 문제