开发者

C# - TabPage Color event

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 e开发者_开发知识库tc. 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.


You can call Invalidate() on the control to force a repaint.


If you have an event fired when your connection state changes you could do an

InvalidateVisual()

on all of your tabs from within that event.


If you want to have a constant refresh going, then you probably need to create System.Timers.Timer object.

Once you create a Timer and set the timer tick value to whatever interval you need (in milliseconds) it will fire the OnTimerTick event at regular intervals. From this event you can trigger a call to your OnDraw method through the Invalidate() method. Invalidate tells the system that your screen needs to be refreshed and it will call OnDraw and OnPaint at the next available opportunity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜