473,394 Members | 1,722 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,394 software developers and data experts.

change backcolor of controls which have focus

hello,
Just a sort of newbie question.
How can i change the backcolor of the controls which have the focus
(textbox/combobox/datetimepicker) and
set it back to white when they lost focus.
thanx in advance
Stefan
Nov 21 '05 #1
13 6881
Use these events:

Private Sub Button1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.GotFocus
Button1.BackColor = .....
End Sub
Private Sub Button1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.LostFocus
Button1.BackColor = .....
End Sub
Hope it helps
Chris

"Stefan" <st@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
hello,
Just a sort of newbie question.
How can i change the backcolor of the controls which have the focus
(textbox/combobox/datetimepicker) and
set it back to white when they lost focus.
thanx in advance
Stefan

Nov 21 '05 #2
Use these events:

Private Sub Button1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.GotFocus
Button1.BackColor = .....
End Sub
Private Sub Button1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.LostFocus
Button1.BackColor = .....
End Sub
Hope it helps
Chris

"Stefan" <st@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
hello,
Just a sort of newbie question.
How can i change the backcolor of the controls which have the focus
(textbox/combobox/datetimepicker) and
set it back to white when they lost focus.
thanx in advance
Stefan

Nov 21 '05 #3
Stefan,
As Chris suggests you can use the GotFocus & LostFocus events for this.

To minimize duplicate code I would consider using:
1. a single event handler for all controls
2. derived controls
3. an ExtenderProvider (implement System.Component.IExtenderProvider)

With #1 you need to add the same "handler" on each form, plus wire all the
controls to the handler.

With #2 you need to derive from every control & remember to use these custom
controls.

With #3 its more work to create the Provider itself (then a single derived
control), however it is then really easy to use the provider on multiple
forms.

I normally favor #2 as invariable I am adding other customizations to the
controls...

Both #2 & #3 are "designer friendly"!

Hope this helps
Jay

"Stefan" <st@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
hello,
Just a sort of newbie question.
How can i change the backcolor of the controls which have the focus
(textbox/combobox/datetimepicker) and
set it back to white when they lost focus.
thanx in advance
Stefan

Nov 21 '05 #4
Stefan,
As Chris suggests you can use the GotFocus & LostFocus events for this.

To minimize duplicate code I would consider using:
1. a single event handler for all controls
2. derived controls
3. an ExtenderProvider (implement System.Component.IExtenderProvider)

With #1 you need to add the same "handler" on each form, plus wire all the
controls to the handler.

With #2 you need to derive from every control & remember to use these custom
controls.

With #3 its more work to create the Provider itself (then a single derived
control), however it is then really easy to use the provider on multiple
forms.

I normally favor #2 as invariable I am adding other customizations to the
controls...

Both #2 & #3 are "designer friendly"!

Hope this helps
Jay

"Stefan" <st@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
hello,
Just a sort of newbie question.
How can i change the backcolor of the controls which have the focus
(textbox/combobox/datetimepicker) and
set it back to white when they lost focus.
thanx in advance
Stefan

Nov 21 '05 #5
Stefan,

When you use this class in your application
\\\
Public Class MyBackGroundColors
Public Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).BackColor = SystemColors.Window
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).BackColor = Color.LightBlue
End Sub
End Class
////
And than this row in every load event of your startupforms.
\\\
Dim mycol As New MyBackGroundColors
mycol.doSet(Me)
Dim frm1 As New Form2
mycol.doSet(frm1) 'and than this for every form you create.
frm1.Show()
////
Than I think you have done it for every form and all your controls.

I hope this helps?

Cor
Nov 21 '05 #6
Stefan,

When you use this class in your application
\\\
Public Class MyBackGroundColors
Public Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).BackColor = SystemColors.Window
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).BackColor = Color.LightBlue
End Sub
End Class
////
And than this row in every load event of your startupforms.
\\\
Dim mycol As New MyBackGroundColors
mycol.doSet(Me)
Dim frm1 As New Form2
mycol.doSet(frm1) 'and than this for every form you create.
frm1.Show()
////
Than I think you have done it for every form and all your controls.

I hope this helps?

Cor
Nov 21 '05 #7
how can i prevent with your solutions buttons
get coloured to. now i'm using the tag property
For Each ctr In parentCtr.Controls
if ctr.tag.tostring <> 'btn' then
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr) end if Next

"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:OM**************@tk2msftngp13.phx.gbl... Stefan,

When you use this class in your application
\\\
Public Class MyBackGroundColors
Public Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).BackColor = SystemColors.Window
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).BackColor = Color.LightBlue
End Sub
End Class
////
And than this row in every load event of your startupforms.
\\\
Dim mycol As New MyBackGroundColors
mycol.doSet(Me)
Dim frm1 As New Form2
mycol.doSet(frm1) 'and than this for every form you create.
frm1.Show()
////
Than I think you have done it for every form and all your controls.

I hope this helps?

Cor

Nov 21 '05 #8
how can i prevent with your solutions buttons
get coloured to. now i'm using the tag property
For Each ctr In parentCtr.Controls
if ctr.tag.tostring <> 'btn' then
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr) end if Next

"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:OM**************@tk2msftngp13.phx.gbl... Stefan,

When you use this class in your application
\\\
Public Class MyBackGroundColors
Public Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).BackColor = SystemColors.Window
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).BackColor = Color.LightBlue
End Sub
End Class
////
And than this row in every load event of your startupforms.
\\\
Dim mycol As New MyBackGroundColors
mycol.doSet(Me)
Dim frm1 As New Form2
mycol.doSet(frm1) 'and than this for every form you create.
frm1.Show()
////
Than I think you have done it for every form and all your controls.

I hope this helps?

Cor

Nov 21 '05 #9
Stefan,

It is easier to use
\\\
If Not TypeOf ctr Is Button then .........
///

I hope this helps?

Cor
Nov 21 '05 #10
Stefan,

It is easier to use
\\\
If Not TypeOf ctr Is Button then .........
///

I hope this helps?

Cor
Nov 21 '05 #11
thanx
"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:OE**************@TK2MSFTNGP11.phx.gbl...
Stefan,

It is easier to use
\\\
If Not TypeOf ctr Is Button then .........
///

I hope this helps?

Cor

Nov 21 '05 #12
thanx
"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:OE**************@TK2MSFTNGP11.phx.gbl...
Stefan,

It is easier to use
\\\
If Not TypeOf ctr Is Button then .........
///

I hope this helps?

Cor

Nov 21 '05 #13
I use Cor's solution.It works fine
thanks to everyone for responding so quick.
greetz,
Stefan

"Stefan" <st@nospam.com> schreef in bericht
news:uM**************@TK2MSFTNGP12.phx.gbl...
hello,
Just a sort of newbie question.
How can i change the backcolor of the controls which have the focus
(textbox/combobox/datetimepicker) and
set it back to white when they lost focus.
thanx in advance
Stefan

Nov 21 '05 #14

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

Similar topics

2
by: Smith Duggan | last post by:
I am attempting to change the background properties of a rectangle in the code, and have been stuck now for a day and a half. This is my first access app. Please be gentle with my steaming pile...
0
by: Stefan | last post by:
hello, Just a sort of newbie question. How can i change the backcolor of the controls which have the focus (textbox/combobox/datetimepicker) and set it back to white when they lost focus. thanx...
0
by: Agnes | last post by:
I had created a textbox usercontrol , My aim is "once the textbox got focus, its backcolor become lightgray", lost focus will change back to default.Please be kind to help. Private Sub...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
7
by: garyusenet | last post by:
I'm using krypton toolkit which has allowed me to make a cool looking form. However, when I set my textbox to disabled it is 'greyed' out. The grey colour isn't in keeping with the office 2007...
3
by: windy | last post by:
I would like to change the backcolor inside the checkbox when the component is on focus, not the color of the text. Thanks a lot.
0
by: Rob | last post by:
hi, in a form with multiple text and comboboxes , i want change the color of the bacground if the control has the focus. If the control is an combox i want also force a dropdown . Can i get...
5
by: Rob | last post by:
Hi, I'am working with vb2005 and it's an ADO application based on an access database. i'am still have problems to get the backcolor of an control in a different color if it has the focus. I am...
4
by: J Lagos | last post by:
I want to change the backcolor of textboxes in a report depending on their value. I messed with this for a few hours but I'm not savvy with the syntax for getting at controls in a report. can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.