Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

C# certainly isn't my strong suit so I appreciate all the generous folk sharing their knowledge. I'm working with a Windows Form and I've read up on events and have found some excellent help on how to modify a TabControl so I can have an OnDraw event that will add some coloring to the tabs.

The color of each tab is based upon the state of a connection variable:
Current (green)
Lost (red)
Stale (yellow)

The OnDraw event works excellent for updating the color of each tab, but that only occurs when the user selects a different tab to view.

What I would like to happen is for the color of each tab to be updated whenever the connection state changes. For example, let's say Tab#1 is colored green, but then the connection state changes to stale so now the tab needs to be colored yellow but it won't get colored like that until the user clicks on a different tab and the OnDraw event is triggered.



So I'm trying to figure out how to do that. When the OnDraw event is triggered normally (by the user clicking on a different tab) a "DrawItemEventArgs" parameter is passed into the even handler. That variable is already populated with the pertinent data needed to figure out which tab was clicked on, the boundaries of that tab and etc. So I am unsure where it came from or how I can programmatically re-create such a call to re-color the tabs whenever the connection variable changes.

Please let me know if I need to clarify anything!
Thank you.
Posted

1 solution

I don’t know how you are verify the connection state but I suppose that you have some kind of trigger to know when the connection is lost and there you add the line to change color.
And when you set the color the visual style doesn’t change, this is why I can assume once I don’t know your code, but here is a tip.

After you change the color use the ‘Invalidate();’ to rebuild your image, so shuld be sonthing like that:

TabPageName.Invalidate();



Hope this help you.
 
Share this answer
 
Comments
zlarsen 6-Jul-10 16:03pm    
I actually needed to do that on the TabControl.

myTabControl.Invalidate();

I did not know that such a call existed and would perform exactly what I need it to do! Turned out simpler than I imagined. Thank you so very much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900