By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Textbox Class question

P: n/a
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?

-Peter
Nov 20 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
I assume you are talking about a Windows Forms application, right?

Public Sub ChangeTextBoxColor(ByVal Sender as System.Object, e as EventArgs)
_
Handles Textbox1.Enter, Textbox2.Enter, Textbox3.Enter, etc., etc.

Dim theTB as TextBox = CType(sender, Textbox)
theTB.BackColor = Color.Blue

End Sub

"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?

-Peter

Nov 20 '05 #2

P: n/a
I agree - or you could add the other text boxes to one of the boxes 'enter'
event - in the handles clause.
I still miss those control arrays - and Recordset -
"Scott M." <s-***@nospam.nospam> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
I assume you are talking about a Windows Forms application, right?

Public Sub ChangeTextBoxColor(ByVal Sender as System.Object, e as EventArgs) _
Handles Textbox1.Enter, Textbox2.Enter, Textbox3.Enter, etc., etc.

Dim theTB as TextBox = CType(sender, Textbox)
theTB.BackColor = Color.Blue

End Sub

"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?

-Peter


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 20 '05 #3

P: n/a
Hal,

There are a lot of control arrays in VBNet.

I have a complete sample using it, I have pasted it bellow. It looks very
much your enter leave problem. Just copy it to a new project and add 2
buttons and a textbox on the form. It is hoovering a button, however for a
textbox it goes the same.

This is one approacht of using an array of controls in VBNet. However you
can as well use for this the control.collection.

However the behaviour of control arrays has changed from VB6 what was a
little bit strange approach. (More a table of all controls of a certaintype
than a control array, how you would deal with that when you by instance
inherit from a control to make an almost the same look alike).

About the dataset you will probably in future always hope that you don't
ever have to use the recordset again.

(The sample from Scott is very good, it is the same as this just an other
approach using the array for setting the handlers, which is here for 2
buttons, however could be a bunch)

I hope this gives some ideas?

Cor

\\\needs two buttons and a label on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim btnArea As Button() = New Button() {Button1, Button2}
For Each btn As Button In btnArea
AddHandler btn.MouseLeave, AddressOf Button_MouseLeave
AddHandler btn.MouseEnter, AddressOf Button_MouseEnter
Next
End Sub
Private Sub Button_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Black
Me.Label1.Text = ""
End Sub
Private Sub Button_MouseEnter(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Red
Me.Label1.Text = DirectCast(sender, Button).Name
End Sub
End Class
///

I agree - or you could add the other text boxes to one of the boxes 'enter' event - in the handles clause.
I still miss those control arrays - and Recordset -
"Scott M." <s-***@nospam.nospam> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
I assume you are talking about a Windows Forms application, right?

Public Sub ChangeTextBoxColor(ByVal Sender as System.Object, e as

EventArgs)
_
Handles Textbox1.Enter, Textbox2.Enter, Textbox3.Enter, etc., etc.

Dim theTB as TextBox = CType(sender, Textbox)
theTB.BackColor = Color.Blue

End Sub

"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?

-Peter


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004

Nov 20 '05 #4

P: n/a

"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?


Create a UserControl and change it to inherit directly from TextBox,
then pop code in the OnGotFocus() routine, as in

[MyTextBox.vb]
Public Class MyTextBox
Inherits System.Windows.Forms.TextBox

Public Overrides Sub OnGotFocus( ...
MyBase.OnGotFocus( ...
Me.BackColor = ...
End Sub

End Class

OK, getting it into the Toolbox to use in other applications is fiddly, but
the code's there and ready to roll ...

HTH,
Phill W.
Nov 20 '05 #5

P: n/a
If you don't mind my asking, why do you want to do that?

--
Jonathan Allen
"Peter" wrote:
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?

-Peter

Nov 20 '05 #6

P: n/a
Why bother with that when regular textboxes already expose an "Enter" event
for receiving focus? Also, you didn't address the real question, which was
the most effective way to have several textboxes and handle the gotFocus of
any of them to change the particular one's back color.
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:ce**********@yarrow.open.ac.uk...

"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?
Create a UserControl and change it to inherit directly from TextBox,
then pop code in the OnGotFocus() routine, as in

[MyTextBox.vb]
Public Class MyTextBox
Inherits System.Windows.Forms.TextBox

Public Overrides Sub OnGotFocus( ...
MyBase.OnGotFocus( ...
Me.BackColor = ...
End Sub

End Class

OK, getting it into the Toolbox to use in other applications is fiddly,

but the code's there and ready to roll ...

HTH,
Phill W.

Nov 20 '05 #7

P: n/a
??? I think it's pretty clear what the OP is trying to do.
"Jonathan Allen" <Jo***********@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
If you don't mind my asking, why do you want to do that?

--
Jonathan Allen
"Peter" wrote:
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?

-Peter

Nov 20 '05 #8

P: n/a
Amazingly enough, I found a article in the knowledgebase that was
written in VB speak not C# speak. LOL.

I created a class in a vb.net application template named Bluetextbox.
At the top I wrote inherits textbox
I compiled the program.

The I added the class to my control box by simply browsing to the new
exe. It took like 1 minute. Making controls in vb.net is so easy
now.

Thank god, now I don't have to type handles...80 million times.

http://msdn.microsoft.com/library/de...rlsampover.asp
Nov 20 '05 #9

P: n/a
Peter,

When you had looked to the approach I took it was as well only creating in a
few lines of code creating all the handles for 80 textboxes.

While it is in the approach from Scott better when you have only some
textboxes.

However that does not mean that your approach is wrong.
When that fits you better take that.

Cor
Nov 20 '05 #10

P: n/a
Scott,

I have some 100 textboxes.... I should of mentioned that.
Nov 20 '05 #11

P: n/a
Thanks for the help. I have been reading book after book on intuitive
user app design and now I'm trying to impliment some of the lessons I
have learned. Thanks for all the posts. This newsgroup audience is
awesome.
Nov 20 '05 #12

P: n/a
Cor,
Thanks - useful info and tip -
Hal

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O9**************@TK2MSFTNGP12.phx.gbl...
Hal,

There are a lot of control arrays in VBNet.

I have a complete sample using it, I have pasted it bellow. It looks very
much your enter leave problem. Just copy it to a new project and add 2
buttons and a textbox on the form. It is hoovering a button, however for a
textbox it goes the same.

This is one approacht of using an array of controls in VBNet. However you
can as well use for this the control.collection.

However the behaviour of control arrays has changed from VB6 what was a
little bit strange approach. (More a table of all controls of a certaintype than a control array, how you would deal with that when you by instance
inherit from a control to make an almost the same look alike).

About the dataset you will probably in future always hope that you don't
ever have to use the recordset again.

(The sample from Scott is very good, it is the same as this just an other
approach using the array for setting the handlers, which is here for 2
buttons, however could be a bunch)

I hope this gives some ideas?

Cor

\\\needs two buttons and a label on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim btnArea As Button() = New Button() {Button1, Button2}
For Each btn As Button In btnArea
AddHandler btn.MouseLeave, AddressOf Button_MouseLeave
AddHandler btn.MouseEnter, AddressOf Button_MouseEnter
Next
End Sub
Private Sub Button_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Black
Me.Label1.Text = ""
End Sub
Private Sub Button_MouseEnter(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Red
Me.Label1.Text = DirectCast(sender, Button).Name
End Sub
End Class
///

I agree - or you could add the other text boxes to one of the boxes

'enter'
event - in the handles clause.
I still miss those control arrays - and Recordset -
"Scott M." <s-***@nospam.nospam> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
I assume you are talking about a Windows Forms application, right?

Public Sub ChangeTextBoxColor(ByVal Sender as System.Object, e as

EventArgs)
_
Handles Textbox1.Enter, Textbox2.Enter, Textbox3.Enter, etc., etc.

Dim theTB as TextBox = CType(sender, Textbox)
theTB.BackColor = Color.Blue

End Sub

"Peter" <pe***@mclinn.com> wrote in message
news:dc**************************@posting.google.c om...
> I'm looking to create multiple textboxs that change to a light blue on > focus. What is the most efficient way to do this?
>
>
>
> -Peter

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 20 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.