51120

C# - TabPage Color event

Question:

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.

Answer1:

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

Answer2:

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.

Answer3:

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.

Recommend

  • How can I query users with an expired password in Active Directory?
  • UPON DUPLICATE KEY increment multiple columns?
  • Component is not unmount after its delete in store
  • Creating Setup of large data with NSIS Script
  • Update SQL MS Access 2010
  • How to change default stop edit behavior in jtable
  • Specify HTTPS for custom WCF Binding
  • Is it safe to drop the -webkit vendor prefix from the css3 border-radius yet?
  • Java : How to tint this PNG programmatically?
  • Are there any side effects from calling SQLAlchemy flush() within code?
  • Making Google Visualization - Annotation Chart to work in GWT
  • Flex items with same property values are rendering in different sizes
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • How to split circle in to the sectors in google maps?
  • Check for zero lines output from command over SSH
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • How can I set a binding to a Combox in a UserControl?
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • MongoDb aggregation
  • Is there a way to do normal logging with EureakLog?
  • How to modify the colors in the legend of a plot using a fill gradient?
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Highlight and Bold text in JTextPane
  • Xamarin Forms - UWP Fonts
  • How to recover from a Spring Social ExpiredAuthorizationException
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • ILMerge & Keep Assembly Name
  • Display Images one by one with next and previous functionality
  • Weird JavaScript statement, what does it mean?
  • Large data - storage and query
  • How do you troubleshoot character encoding problems?
  • WOWZA + RTMP + HTML5 Playback?
  • How to format a variable of double type
  • PHP: When would you need the self:: keyword?
  • Acquiring multiple attributes from .xml file in c#
  • Android Google Maps API OnLocationChanged only called once
  • reshape alternating columns in less time and using less memory
  • How to Embed XSL into XML
  • How can I use threading to 'tick' a timer to be accessed by other threads?