backcolor

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

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 searching for a routine which automacticly highligt the control
(textbox, cbo, groupbox) if he is focused instead to program each control
separatly by gotfocus and lostfocus. (Me.BackColor = Color.YellowGreen)

IS there somebody who can help me through this problem ??

regard, rob
 
Rob,

This is very simple to do in VB, be aware that some controls don't have a
backcolor.

\\\
Private Sub MyControls_GotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles ComboBox1.GotFocus, ListBox1.GotFocus, TextBox1.GotFocus
DirectCast(sender, Control).BackColor = Color.DarkRed
End Sub

Private Sub MyControls_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles ComboBox1.LostFocus, ListBox1.LostFocus,
TextBox1.LostFocus
DirectCast(sender, Control).BackColor = Color.DarkGreen
End Sub
///

Did you know that a better newsgroup to ask this kind of question for VB is
microsoft.public.dotnet.languages.vb

Succes

Cor
 
Hi,

it seems my vb does not recognize the names of the controls. he underscore
the name of the controls
Private Sub MyControls_GotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) _

Handles ComboBox1.GotFocus, ListBox1.GotFocus, TextBox1.GotFocus

DirectCast(sender, Control).BackColor = Color.DarkRed

End Sub

If i see it right i've to put the name of each control separatly after the
handels. I 've to much controls to achieve this. is it posible to handels
mycontrols.gotfocus instead ?



mvg Rob
 
Rob,

As you have a question, then please make it clear in one time.
There is not any problem to set a ton of controls that should be handled at
the metode.

You can of course as well use the more retro like method as with delegates
to set addresses at a windows message that tells which method should be
handled. (You can even use delegates as you want that).

Something like

\\\
For each ctrl in controls
addhandler ctr.lostfocus, addressOf MyControls_LostFoscus
addhandler ctr.gotfocus, addressOfMycontrols_Gotfocus
next
///

Be aware that if you have controls in a groupbox, a panel or any other
control you have to do this recursive.

Cor
 
Hi Cor,

is am a beginner to program in vb and also my english is not as fluent as i
would be , but never the less I try to improve my english.
About the code you wrote, if i put this code into the load of a form I get
an error tells me that "addressOfMycontrols_Gotfocus" is not declared.

what do you mean by "if you have controls in a groupbox, a panel or any
other
control you have to do this recursive."

Most of my controls are been ordened into tabpage and groupboxes !

mvg Rob
 
Rob,

My English is too not as fluent as I wish it would be.

However you and I are not the only ones, I see people which are from
countries where they use English writting crapy too.

(there is a Dutch developper newsgroup, but in that is only one person
active).

However, as you are a beginner than just start with adding the events to the
procedures.

A control is added always to its parent control from which the form is
mostly the top.

Form.Controls
contains by instance
Groubbox.controls
contains by instance
Textbox1

You have to go through all those controls what is the most simple done
recursevily

A sample
http://www.vb-tips.com/ClearTextBox.aspx

addressOf MyControls_Gotfocus 'as in my previous sample.
The second one is a simple typo.

Cor
 
Back
Top