473,836 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1481
I assume you are talking about a Windows Forms application, right?

Public Sub ChangeTextBoxCo lor(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.c om> wrote in message
news:dc******** *************** ***@posting.goo gle.com...
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.nosp am> wrote in message
news:uH******** ******@TK2MSFTN GP12.phx.gbl...
I assume you are talking about a Windows Forms application, right?

Public Sub ChangeTextBoxCo lor(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.c om> wrote in message
news:dc******** *************** ***@posting.goo gle.com...
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.collect ion.

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(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim btnArea As Button() = New Button() {Button1, Button2}
For Each btn As Button In btnArea
AddHandler btn.MouseLeave, AddressOf Button_MouseLea ve
AddHandler btn.MouseEnter, AddressOf Button_MouseEnt er
Next
End Sub
Private Sub Button_MouseLea ve(ByVal sender As Object, _
ByVal e As System.EventArg s)
DirectCast(send er, Button).BackCol or = Color.Black
Me.Label1.Text = ""
End Sub
Private Sub Button_MouseEnt er(ByVal sender As Object, _
ByVal e As System.EventArg s)
DirectCast(send er, Button).BackCol or = Color.Red
Me.Label1.Text = DirectCast(send er, 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.nosp am> wrote in message
news:uH******** ******@TK2MSFTN GP12.phx.gbl...
I assume you are talking about a Windows Forms application, right?

Public Sub ChangeTextBoxCo lor(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.c om> wrote in message
news:dc******** *************** ***@posting.goo gle.com...
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.c om> wrote in message
news:dc******** *************** ***@posting.goo gle.com...
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.OnGotFoc us( ...
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.c om> wrote in message
news:dc******** *************** ***@posting.goo gle.com...
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.OnGotFoc us( ...
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.mic rosoft.com> wrote in message
news:C9******** *************** ***********@mic rosoft.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2619
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 that I want to send values to. I then have another function named ReadData (namespace=OtherName, class=OtherClass). I have a while loop that reads data and I want this function to be able to AppendText to the tbOutput textbox. I can't seem to...
5
3304
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, combos, etc, with a blue backcolor, to be used on all my forms. I compiled this, but when I use it on my form, the custom control properties are not being set. What am I missing here? Many thanks!
6
3221
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 public System.Windows.Forms.TextBox textBox1; When I try to write to this textbox it never publishes anything. If I call the same method from inside the same class it does. How can I publish to this textbox from an external class. Simple...
14
2987
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 search in google and found a way with changing the CultureInfo but still didn't work on a TextBox. i'm sure there's a way to do that, but i don't know what's the way. I'm desperate, if some one knows the answer, i will be very thankful to know...
28
4381
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 added a class to project and it's named XmlApi(). In the XmlAPI() class I have simple code as following XmlAPI() { string str = "Some Text";
2
8408
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 submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
0
1400
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. Question #1: In the Add button Command Event I am trying to access the Text value of the TextBox in the other Footer columns. However, inside the Event, the TextBox.Text values are all empty strings, even if they had data typed into them. Is this a...
10
1617
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 System.Windows.Forms.TextBox Public Class DerivedTextBox Inherits TextBox
0
1621
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" ReadOnly="True" EnableViewState="False"></asp:textbox> <label class="col3">Rm Phone</label> <asp:textbox id="txtRmPhone" runat="server" cssclass="col4" ReadOnly="True"
1
3245
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' & 'Cancel'). Till this point, no problem. Initially, the TextBox is empty. The Button has a property named 'ConfirmMessage' so that the developer using this custom control can modify the question in the confirm dialog. If the user clicks 'OK', I want the...
0
9825
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9672
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10559
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10260
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9388
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4460
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.