473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Textbox Class question

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
12 1425
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
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
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

"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
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
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
??? 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
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
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
Scott,

I have some 100 textboxes.... I should of mentioned that.
Nov 20 '05 #11
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim | last post by:
Hello All, Sorry for the newbie question, but here goes: I have a form named MainForm (namespace=MyFormProject, class=MainForm). In that form is a textbox tbOutput. This is a multi-line textbox...
5
by: Steven C | last post by:
Hello: This should be a simply question for most of you guys. Obviously, I'm new to C#. I'm trying to add a base form objects base class to my project, so I can pre-configure textboxes,...
6
by: JP | last post by:
I'm sure this is a simple question and I'm overlooking the obvious. But, I have two seperate classes (in seperate files) under the same namespace. I am calling a method in one class that contains...
14
by: Gidi | last post by:
Hi, For the last week, i'm looking for a way to make a TextBox always write in English (No matter what the OS default language is). i asked here few times but the answers i got didn't help me. i...
28
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
0
by: jason | last post by:
Hello everyone. I am trying to write some custom command events into a DataGrid. The command that is currently giving me trouble is an "Add" custom command in the footer of a template column. ...
10
by: Rob | last post by:
Question : I want to create a read only TextBox that does not respond to any input from the keyboard, therefore I came up with the following derived class : Option Strict On Imports...
0
by: CharlesA | last post by:
Hi folks, I'm using ASP.net 1.1 with C# I've got this kind of thing going <div class="row"> <label class="col1">Rm Name</label> <asp:textbox id="txtRM" runat="server" cssclass="col2"...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.