|
-
Sep 21st, 2011, 03:26 PM
#1
Thread Starter
Addicted Member
text "hatch(?)ing"
hey guys i need to know how to get a text of a textbox "blued" if focus = true
... for not clicking twice.... i mean when you click, background of the text become blue and what you write is replaced with the text...(i dont know what that is called)
-
Sep 21st, 2011, 04:43 PM
#2
Re: text "hatch(?)ing"
Use Enter and Leave event of a TextBox to alter the background color as shown here where there are three TextBox controls.
Code:
Public Class Form3
Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter
CType(sender, TextBox).BackColor = Color.Blue
End Sub
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave
CType(sender, TextBox).BackColor = Color.FromName("Window")
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
ActiveControl = TextBox3
End Sub
End Class
-
Sep 21st, 2011, 10:36 PM
#3
Thread Starter
Addicted Member
Re: text "hatch(?)ing"
thanks for your answer but i dont think your code will help me but im not sure anyways....my most important goal was not coloring the background...it was the ability of changing a text with getting focus into that textbox and by pressing a button...
e.g: a text of textbox1 is "123" and i click to that textbox only once...and then press 5 once and the last text is not including "123" in it i hope you understand it and if your code does that im sorry(tell me if it works for that but it didnt seem to doing that).....i got to go ....
-
Sep 21st, 2011, 10:51 PM
#4
Re: text "hatch(?)ing"
I think, this is what you are looking for (if I understand your question):
vb.net Code:
Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
TextBox1.SelectAll()
End Sub
The SelectAll() of a TextBox will highlight all the text inside it(the blue background that you are referring to seems to be this highlighting). So, you could simply call this method in the Click() event of the TextBox.
Thus whenever you click on the TextBox, the Click() event is fired and this will call the TextBox's SelectAll() method.
Hope this helps
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Sep 21st, 2011, 11:16 PM
#5
Re: text "hatch(?)ing"
I don't think that handling the Click event is the answer. If you do that, whenever the user tries to click to place the caret within the text, all the text will be selected. It would make more sense to handle the Enter event, so that all the text is selected every time the control receives focus, by mouse or keyboard. That allows the user to click the text while the control already has focus to position the cursor. If the control already has focus and the user wants to select all the text then they just use Ctrl+A, which is the universal Windows shortcut for select all.
-
Sep 22nd, 2011, 05:11 PM
#6
Thread Starter
Addicted Member
Re: text "hatch(?)ing"
but i have a lot of textbox must have this procedure how can i make the code handles them all(cant write all of them almost 50 or 60)
-
Sep 22nd, 2011, 07:36 PM
#7
Re: text "hatch(?)ing"
 Originally Posted by ugur
but i have a lot of textbox must have this procedure how can i make the code handles them all(cant write all of them almost 50 or 60)
Select them all in the designer, open the Properties window, click the Events button and then double-click the desired event. That will create one event handler with all controls in the Handles clause. You can also later select one or more controls and then select the existing event handler from the drop-down in the Properties window.
-
Sep 23rd, 2011, 01:56 PM
#8
Thread Starter
Addicted Member
Re: text "hatch(?)ing"
 Originally Posted by jmcilhinney
Select them all in the designer, open the Properties window, click the Events button and then double-click the desired event. That will create one event handler with all controls in the Handles clause. You can also later select one or more controls and then select the existing event handler from the drop-down in the Properties window.
Code:
Private Sub TextBox4_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.Enter, TextBox6.Enter, TextBox4.Enter, TextBox1.Enter, kS3.Enter, kS2.Enter, kS1.Enter, Cnc.Enter
'i couldnt figure out what to write here...???
End Sub
-
Sep 23rd, 2011, 02:13 PM
#9
Re: text "hatch(?)ing"
Code:
Private Sub TextBox4_Enter(sender As Object, e As EventArgs) Handles TextBox4.Enter, TextBox3.Enter, TextBox2.Enter, TextBox1.Enter
Dim txt As TextBox = DirectCast(sender, TextBox)
txt.SelectAll()
End Sub
-
Sep 23rd, 2011, 04:37 PM
#10
Thread Starter
Addicted Member
Re: text "hatch(?)ing"
 Originally Posted by BlindSniper
Code:
Private Sub TextBox4_Enter(sender As Object, e As EventArgs) Handles TextBox4.Enter, TextBox3.Enter, TextBox2.Enter, TextBox1.Enter
Dim txt As TextBox = DirectCast(sender, TextBox)
txt.SelectAll()
End Sub
thank you
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
|