DUVIDA MENOR QUE VB.NET
Me desculpem por fazer muitas perguntas mas estou querendo aprender a programar e aqui e o unico lugar que achei para tirar minhas duvidas, mas vamos lá.
Recentemente fiz uma pergunta de como fazer um click em um botao e aumentar 1 na label, agora quero saber como eu faço para quando a label estiver menos de 500, o botao 2 nao ficar ativado, e quando estiver mais de 500 o botao 2 ficar ativado, meu código é este
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
lblclick.Text = lblclick.Text + 1
If lblclick.Text = 500 Then
Button2.Enabled = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
lblclick.Text = lblclick.Text - 500
End Sub
End Class
Recentemente fiz uma pergunta de como fazer um click em um botao e aumentar 1 na label, agora quero saber como eu faço para quando a label estiver menos de 500, o botao 2 nao ficar ativado, e quando estiver mais de 500 o botao 2 ficar ativado, meu código é este
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
lblclick.Text = lblclick.Text + 1
If lblclick.Text = 500 Then
Button2.Enabled = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
lblclick.Text = lblclick.Text - 500
End Sub
End Class
Você pode usar o evento TextChanged (Ao atualizar o Text da Label), conforme abaixo:
Private Sub lblclick_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblclick.TextChanged
If lblclick.Text < 500 Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End Sub
ROBIU, aqui nao funcionou não cara, eu fiz um botao que gastasse 500, que seria este, e um botao que gastasse 1000, quando fiquei com 1000, gastei e fiquei com 0, mas o botao 2 continuou ativo
posta o código ou o projeto
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
lblclick.Text = lblclick.Text + 1
If lblclick.Text < 500 Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
If lblclick.Text = 1000 Then
Button5.Enabled = True
End If
If lblclick.Text = 2000 Then
Button4.Enabled = True
End If
If lblclick.Text = 5000 Then
Button3.Enabled = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
lblclick.Text = lblclick.Text - 500
Button2.Enabled = False
Timer1.Start()
Timer5.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblclick.Text = lblclick.Text + 1
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
lblclick.Text = lblclick.Text + 10
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Timer2.Start()
Timer6.Start()
Button5.Enabled = False
lblclick.Text = lblclick.Text - 1000
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Timer3.Start()
Timer7.Start()
Button4.Enabled = False
lblclick.Text = lblclick.Text - 2000
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer4.Start()
Timer8.Start()
Button3.Enabled = False
lblclick.Text = lblclick.Text - 5000
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
lblclick.Text = lblclick.Text + 20
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
lblclick.Text = lblclick.Text + 50
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
Button2.Enabled = False
End Sub
Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
Button5.Enabled = False
End Sub
Private Sub Timer7_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer7.Tick
Button4.Enabled = False
End Sub
Private Sub Timer8_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer8.Tick
Button3.Enabled = False
End Sub
Private Sub lblclick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblclick.Click
End Sub
End Class
Ta ai o codigo
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
lblclick.Text = lblclick.Text + 1
If lblclick.Text < 500 Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
If lblclick.Text = 1000 Then
Button5.Enabled = True
End If
If lblclick.Text = 2000 Then
Button4.Enabled = True
End If
If lblclick.Text = 5000 Then
Button3.Enabled = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
lblclick.Text = lblclick.Text - 500
Button2.Enabled = False
Timer1.Start()
Timer5.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblclick.Text = lblclick.Text + 1
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
lblclick.Text = lblclick.Text + 10
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Timer2.Start()
Timer6.Start()
Button5.Enabled = False
lblclick.Text = lblclick.Text - 1000
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Timer3.Start()
Timer7.Start()
Button4.Enabled = False
lblclick.Text = lblclick.Text - 2000
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer4.Start()
Timer8.Start()
Button3.Enabled = False
lblclick.Text = lblclick.Text - 5000
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
lblclick.Text = lblclick.Text + 20
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
lblclick.Text = lblclick.Text + 50
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
Button2.Enabled = False
End Sub
Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
Button5.Enabled = False
End Sub
Private Sub Timer7_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer7.Tick
Button4.Enabled = False
End Sub
Private Sub Timer8_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer8.Tick
Button3.Enabled = False
End Sub
Private Sub lblclick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblclick.Click
End Sub
End Class
Ta ai o codigo
Não está funcionando porque você não colocou o código no evento correto. Tem que ser como postei acima, no evento TextChanged da Label.
Quando eu coloquei no evento da label, quando chegava em 500 o botao nem ativava.
Como eu pego o evento Text Changed da label? Quando clico duas vezes ele entra no labelclick.
Funcionou tranquilamente, copiei e colei o seu codigo aqui e funcionou, só nao entendi como você pegou o evento Text Changed da Label, pode me dizer?
Click duplo na Label para ir para a janela de código depois na segunda combo, seleciona o evento TextChanged
Obrigado mesmo, agora vou fazer um joguinho tipo cookie clicker hahaha
Tópico encerrado , respostas não são mais permitidas