Jump to content
zephirus

GotFocus e LostFocus em MainForm

Recommended Posts

zephirus

Olá,

Estou a dar em maluco com uma dúvida muito simples. Só encontro exemplos para controles e nada para a MainForm ou Form1.

Tenho a minha janela principal do meu programa, "MainForm" e quero mudar o text de um label consoante a form tem o focus ou não. O código que tenho é este:

	Sub MainFormGotFocus(sender As Object, e As EventArgs) Handles MainForm.GotFocus
	Label10.Text = "Selected"
End Sub

Sub MainFormLostFocus(sender As Object, e As EventArgs) Handles MainForm.LostFocus
	Label10.Text = "Not Selected"
End Sub

Isto dá um erro:

Handles clause requires a WithEvents variable defined in the containing type or one of its base types. (BC30506)

Eu sei por o WithEvents num controle mas na MainForm não estou a conseguir. Alguém me pode ajudar?

Obrigado.

Share this post


Link to post
Share on other sites
Weasel

Não são esses eventos que deves usar e sim estes:

Private Sub MainForm_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
         Label10.Text = "Selected"
End Sub

Private Sub MainForm_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
        Label10.Text = "Not Selected"
End Sub


Knowledge to the masses


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.