473,320 Members | 1,977 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,320 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 6865
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.