Results 1 to 9 of 9

Thread: [RESOLVED] Back Color on Focus

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Resolved [RESOLVED] Back Color on Focus

    Hi

    When DataGridView1 has focus, ie, the user is entering data, i'd like tool strip 6 to be color.Firebrick

    and when somewhere else on the form is clicked, toolstrip 6 should be color.gray

    Code:
    Private Sub DataGridView1_GotFocus(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.GotFocus
            ToolStrip6.BackColor = Color.Firebrick
    
        End Sub
    this code doesnt seem to work...any help is welcome

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Back Color on Focus

    Is your issue that it doesn't change to "firebrick," or that it doesn't change back to gray?

    Do you have a "LostFocus" sub that changes it back?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: Back Color on Focus

    Hi! The issue is that it doesn't change to firebrick to begin with. I have the "lost focus" sub but can't check that until the first one works.

  4. #4
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Back Color on Focus

    I tried to emulate what you're doing. I put a textbox, a toolstrip and a datagrid on a form (in that order). I changed the toolstrip name to TS, but left the others as their default.

    This code does what you're attempting. See if it works for you when you tab through the controls:

    Code:
    Public Class Form1
    
        Private Sub DataGridView1_GotFocus(sender As Object, e As System.EventArgs) Handles DataGridView1.GotFocus
            Me.Text = "Focus"
            TS.BackColor = Color.Red
        End Sub
    
        Private Sub DataGridView1_LostFocus(sender As Object, e As System.EventArgs) Handles DataGridView1.LostFocus
            TS.BackColor = Color.Gray
        End Sub
    End Class
    PS: I used red as an example, but it works with firebrick, too.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: Back Color on Focus

    That's it working! Many thanks indeed!

  6. #6
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [RESOLVED] Back Color on Focus

    You're welcome. Glad to have helped!

    Just out of curiosity, what did you change?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: [RESOLVED] Back Color on Focus

    the only thing i changed was the tool strip name, changed it to "TS" as in the code, and that seemed to click it over...i should really have changed it earlier :S

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: [RESOLVED] Back Color on Focus

    interestingly, i've now got the same problem with a web browser control...i've changed the name and it won't work...wonder what the problem is with that...

  9. #9
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: [RESOLVED] Back Color on Focus

    Try creating a different event after you changed the name. Some of the experts will explain this better than I will, but, when you change the name of a control after you already have events associated with it, something gets messed up with the syntax in your existing event.

    That doesn't sound very clear...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width