What the deal?

  • Thread starter Thread starter buc
  • Start date Start date
B

buc

I have created a simple login keyboard with QWERTY keys with a user textbox
and password textbox. When I press a key the text goes into both boxes....?
The focus event on both boxes eval to TRUE. Why? this is driving me nuts,
must be a simple answer. Here's code
I named each letter button its own letter (The 'A' button is named A..Etc.)
I shortened the A.Click, B.click code handles for this post because there
were 26 of them.

Private Sub Q_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Q.Click, W.Click, E.Click, R.Click, T.Click,
Y.Click............rest of them

If txtUser.Focus = True Then txtUser.Text = txtUser.Text &
UCase(CType(sender, Button).Text)
If txtPass.Focus = True Then txtPass.Text = txtPass.Text &
UCase(CType(sender, Button).Text)

End Sub
The letter is put in both boxes, and even the DEBUGGER says both focuses are
true?? This is the only code in my program right now..
Any Ideas?..... Thanks BUC
 
Hi,

Textbox.focus will return true if the textbox recieves focus. I
think the property you are looking for is focused.

http://msdn.microsoft.com/library/d...fsystemwindowsformscontrolclassfocustopic.asp

http://msdn.microsoft.com/library/d...ystemwindowsformscontrolclassfocusedtopic.asp

Ken
-------------------
I have created a simple login keyboard with QWERTY keys with a user textbox
and password textbox. When I press a key the text goes into both boxes....?
The focus event on both boxes eval to TRUE. Why? this is driving me nuts,
must be a simple answer. Here's code
I named each letter button its own letter (The 'A' button is named A..Etc.)
I shortened the A.Click, B.click code handles for this post because there
were 26 of them.

Private Sub Q_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Q.Click, W.Click, E.Click, R.Click, T.Click,
Y.Click............rest of them

If txtUser.Focus = True Then txtUser.Text = txtUser.Text &
UCase(CType(sender, Button).Text)
If txtPass.Focus = True Then txtPass.Text = txtPass.Text &
UCase(CType(sender, Button).Text)

End Sub
The letter is put in both boxes, and even the DEBUGGER says both focuses are
true?? This is the only code in my program right now..
Any Ideas?..... Thanks BUC
 
How can you name your A button A & so on?

Why have you got both Username & Password focus to true at the same time?

I am slightly confused by your post. Please clarify
 
Hi,

In the visual studio options->text editor->basic uncheck the hide
advanced members check box. The code you are using set the focus to the
first textbox then sets the focus to the second textbox. Actually since you
are clicking on a button to add to textbox the button has the focus. Try
something like this

Dim bPassword As Boolean = False



Private Sub txtUser_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtUser.TextChanged

bPassword = False

End Sub

Private Sub txtPassword_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtPassword.TextChanged

bPassword = True

End Sub



Private Sub Q_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Q.Click, W.Click, E.Click, R.Click, T.Click,
Y.Click............rest of them

If bPassword Then
txtUser.Text = txtUser.Text & UCase(CType(sender, Button).Text)
Else
txtPass.Text = txtPass.Text & UCase(CType(sender, Button).Text)
End if

End Sub


Ken
----------------------------
According to MSDN .focus sets focus OR returns a true/false as to
whether a control has focus or not. Im am simply checking what textbox
currently has focus to know where to put the alphabetic letter that they
user just pressed. I can't figure out why this code is failing, How can 2
controls have focus at the same time.? Event if I do a a txtUser.Focus(),
which actually sets focus, it code still returns that both have focus.. Any
ideas... I couldn't find a FOCUSED command..
 
According to MSDN .focus sets focus OR returns a true/false as to
whether a control has focus or not. Im am simply checking what textbox
currently has focus to know where to put the alphabetic letter that they
user just pressed. I can't figure out why this code is failing, How can 2
controls have focus at the same time.? Event if I do a a txtUser.Focus(),
which actually sets focus, it code still returns that both have focus.. Any
ideas... I couldn't find a FOCUSED command..
 
Never mind, I found the focused in the MSDN, but it is not an available
option when I type txtUser. , only FOCUS shows up. If I hand jam the
..FOCUSED method, it doesn't error out though. Wow, thats weird.. I guess I
got focus mixed up. It works fine now.. Just couldn't find the .focused in
the intellisense. Thanks
 
Focus is a method, not a property. It returns true if the control
successfully receives focus. To see if a control has the focus, use
the Focused property. As Ken said, go into the options for VB and
uncheck the "Hide Advanced Members" option. Then Focused will be seen
in intellisense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top