|
-
Nov 2nd, 2007, 05:41 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Append a char to a textbox that was selected
Hi!!
In a form how to get the control that currently has focus, knowing that it can be inside a groupbox?
Last edited by Lasering; Nov 2nd, 2007 at 06:11 PM.
-
Nov 2nd, 2007, 05:45 PM
#2
Re: [2005] How to get the current control with Focus?
Me.ActiveControl will return the control that currently has focus.
-
Nov 2nd, 2007, 06:11 PM
#3
Thread Starter
Fanatic Member
Re: [2005] How to get the current control with Focus?
I thought that would help but it didnt!
Here my problem: I have 3 multiline textbox. And a lot of buttons: Alpha, Beta, Gamma, etc. The idea is when u click on a button for example Alpha he appends the character alpha to the previously selected textbox text. For example u had selected the first textbox and then hit alpha, he would append and a alpha to the first textbox text, but if u had the second textbox selected and then hit alpha he would add to the second textbox.
How can i do this?
-
Nov 2nd, 2007, 06:16 PM
#4
Re: [2005] Append a char to a textbox that was selected
I would do something like this:
VB.Net Code:
Public Class Form1
Private focusedTextBox As TextBox
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
focusedTextBox = TextBox1
End Sub
Private Sub TextBox2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.GotFocus
focusedTextBox = TextBox2
End Sub
Private Sub TextBox3_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.GotFocus
focusedTextBox = TextBox3
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
focusedTextBox.AppendText("something")
End Sub
End Class
-
Nov 4th, 2007, 01:33 AM
#5
Re: [2005] Append a char to a textbox that was selected
Don't use the GotFocus event. As specified in the documentation you should use the Enter event. You could also use one method to handle the event for all TextBoxes and assign the sender to the member variable.
Also, you may be interested in using a Button that doesn't take focus when you click it. If so then follow the Onscreen Keyboard link in my signature.
-
Nov 4th, 2007, 08:59 AM
#6
Thread Starter
Fanatic Member
Re: [2005] Append a char to a textbox that was selected
I end up for not using the GotFocus neither the Enter event because i needed the position of the caret when the user unselects the textbox. So later i could insert the char i want (the one respectively to the button), into the "actual caret position"
-
Nov 4th, 2007, 06:07 PM
#7
Re: [RESOLVED] [2005] Append a char to a textbox that was selected
That's of no consequence. The SelectionStart and SelectionLength properties of a TextBox don't change when it loses focus. If you want to insert text into a TextBox at the caret position you just set its SelectedText property, whether it has focus or not.
-
Nov 5th, 2007, 08:27 AM
#8
Thread Starter
Fanatic Member
Re: [RESOLVED] [2005] Append a char to a textbox that was selected
Thks a lot that detail "The SelectionStart and SelectionLength properties of a TextBox don't change when it loses focus" really maded a difference.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|