|
-
Jan 19th, 2012, 08:25 AM
#1
Thread Starter
Addicted Member
[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
-
Jan 19th, 2012, 08:33 AM
#2
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?
-
Jan 19th, 2012, 08:35 AM
#3
Thread Starter
Addicted Member
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.
-
Jan 19th, 2012, 08:47 AM
#4
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.
-
Jan 19th, 2012, 08:53 AM
#5
Thread Starter
Addicted Member
Re: Back Color on Focus
That's it working! Many thanks indeed!
-
Jan 19th, 2012, 08:54 AM
#6
Re: [RESOLVED] Back Color on Focus
You're welcome. Glad to have helped!
Just out of curiosity, what did you change?
-
Jan 19th, 2012, 08:55 AM
#7
Thread Starter
Addicted Member
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
-
Jan 19th, 2012, 09:01 AM
#8
Thread Starter
Addicted Member
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...
-
Jan 19th, 2012, 09:51 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|