Windows Vista Forums

backcolor
  1. #1


    Rob Guest

    backcolor

    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






      My System SpecsSystem Spec

  2. #2


    Cor Ligthert[MVP] Guest

    Re: backcolor

    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


    "Rob" <ROb@xxxxxx> schreef in bericht
    news:efhaA%23jzIHA.3972@xxxxxx

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

      My System SpecsSystem Spec

  3. #3


    Rob Guest

    Re: backcolor

    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

    "Cor Ligthert[MVP]" <notmyfirstname@xxxxxx> schreef in bericht
    news:986B3AEC-DA8C-4E35-818C-861E01FC142E@xxxxxx

    > 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
    >
    >
    > "Rob" <ROb@xxxxxx> schreef in bericht
    > news:efhaA%23jzIHA.3972@xxxxxx

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


      My System SpecsSystem Spec

  4. #4


    Cor Ligthert[MVP] Guest

    Re: backcolor

    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


    "Rob" <ROb@xxxxxx> schreef in bericht
    news:uxibX4wzIHA.2408@xxxxxx

    > 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
    >
    > "Cor Ligthert[MVP]" <notmyfirstname@xxxxxx> schreef in bericht
    > news:986B3AEC-DA8C-4E35-818C-861E01FC142E@xxxxxx

    >> 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
    >>
    >>
    >> "Rob" <ROb@xxxxxx> schreef in bericht
    >> news:efhaA%23jzIHA.3972@xxxxxx

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

      My System SpecsSystem Spec

  5. #5


    Rob Guest

    Re: backcolor

    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

    "Cor Ligthert[MVP]" <notmyfirstname@xxxxxx> schreef in bericht
    news:2FF04C76-E391-43A4-988D-19E7A9900EF6@xxxxxx

    > 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
    >
    >
    > "Rob" <ROb@xxxxxx> schreef in bericht
    > news:uxibX4wzIHA.2408@xxxxxx

    >> 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
    >>
    >> "Cor Ligthert[MVP]" <notmyfirstname@xxxxxx> schreef in bericht
    >> news:986B3AEC-DA8C-4E35-818C-861E01FC142E@xxxxxx

    >>> 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
    >>>
    >>>
    >>> "Rob" <ROb@xxxxxx> schreef in bericht
    >>> news:efhaA%23jzIHA.3972@xxxxxx
    >>>> 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
    >>>>
    >>>>
    >>>>
    >>>
    >>
    >>
    >


      My System SpecsSystem Spec

  6. #6


    Cor Ligthert[MVP] Guest

    Re: backcolor


    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

    >>an error tells me that "addressOfMycontrols_Gotfocus" is not declared.
    addressOf MyControls_Gotfocus 'as in my previous sample.
    The second one is a simple typo.

    Cor


    "Rob" <ROb@xxxxxx> schreef in bericht
    news:OLDRK6$zIHA.4416@xxxxxx

    > Hi Cor,
    >

    >
    > 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
    >
    > "Cor Ligthert[MVP]" <notmyfirstname@xxxxxx> schreef in bericht
    > news:2FF04C76-E391-43A4-988D-19E7A9900EF6@xxxxxx

    >> 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
    >>
    >>
    >> "Rob" <ROb@xxxxxx> schreef in bericht
    >> news:uxibX4wzIHA.2408@xxxxxx

    >>> 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
    >>>
    >>> "Cor Ligthert[MVP]" <notmyfirstname@xxxxxx> schreef in bericht
    >>> news:986B3AEC-DA8C-4E35-818C-861E01FC142E@xxxxxx
    >>>> 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
    >>>>
    >>>>
    >>>> "Rob" <ROb@xxxxxx> schreef in bericht
    >>>> news:efhaA%23jzIHA.3972@xxxxxx
    >>>>> 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
    >>>>>
    >>>>>
    >>>>>
    >>>>
    >>>
    >>>
    >>
    >
    >

      My System SpecsSystem Spec

backcolor problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
backcolor Georg .NET General 1 18 May 2009
change backcolor on focus Rob .NET General 0 20 May 2008