Click here to Skip to main content
13,550,805 members
Click here to Skip to main content
Add your own
alternative version


45 bookmarked
Posted 22 Feb 2004

Visual Studio .NET style status bar

, 22 Feb 2004
Rate this:
Please Sign up or sign in to vote.
An article on an owner drawn flicker free status bar


I have always loved the Visual Studio .NET style interface, and when I tried to "copy" it to my own project, the owner drawn StatusBarPanel always flickered when I try some fast update like displaying mouse positions when mouse is moving. This project demonstrates how to do a flicker free drawing of the status bar in C#, it looks like the same as the Visual Studio .NET one, except mine cannot display animated icon yet (Visual Studio .NET can show an animated icon when you save files).

How to make it flicker free

Owner drawn status bar, we need to overwrite the OnDrawItem or add an event handler for DrawItem.And the Style of the StatusBarPanel must set to StatusBarPanelStyle.OwnerDraw.

// by event handler
MessagePanel.BorderStyle = StatusBarPanelBorderStyle.None;
MessagePanel.Style = StatusBarPanelStyle.OwnerDraw;
this.DrawItem +=new StatusBarDrawItemEventHandler(
protected void DotNetStatusBar_DrawItem(
  object sender, StatusBarDrawItemEventArgs sbdevent)

  // some drawing codes for a panel

This function can do the owner drawing but still cannot avoid flickering. This is because each time the status bar needs to be redrawn, its background got redrawn first. Even if we overwrite the OnPaintBackground function, or we set the style to ControlStyles.Opaque, the background still keeps getting redrawn.

My way of avoiding flicker is to use a double buffer, i.e. set the style to ControlStyles.DoubleBuffer.

this.SetStyle( ControlStyles.AllPaintingInWmPaint 
    | ControlStyles.UserPaint 
    | ControlStyles.DoubleBuffer, true);

To fully enable double-buffering, you must also set the UserPaint and AllPaintingInWmPaint style bits to true. And just because of this UserPaint style, we must overwrite the OnPaint function. In this function, you need to do all the status bar and panels drawings by yourself.

protected override void OnPaint(PaintEventArgs e) 
  int iStart = 0; 
  StatusBarDrawItemEventArgs ea = 
    new StatusBarDrawItemEventArgs(e.Graphics,Font, 
    new Rectangle(iStart,2,MessagePanel.Width-2,Height-1),

Things to do

I did this code only for my own project, so it is not very general. Things can be done like make it a custom control compatible with Visual Studio .NET. Also more exploration can be done on how to display animated icons, progress bars...


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Zhang Songling
Web Developer
China China
Zhang Songling is a programmer, he graduated from National University of Singapore at 2003. Now he is working in a high tech semicon software company in Singapore.

You may also be interested in...

Comments and Discussions

General很好! Pin
qingtianyu911-Jan-08 13:55
memberqingtianyu911-Jan-08 13:55 
GeneralGrats... this did it :) Pin
Roland Gollenbeck16-Dec-04 1:25
sussRoland Gollenbeck16-Dec-04 1:25 
Found this article when searching for how to make an owner drawn list box flicker free...
tried about 10 different clues that did not work...

Then i found yours... some modifications for my listbox and see, it works...

-> i will print this article and stick it at my board... Youre the flicker master Wink | ;)
GeneralDetermining screen size for resizing grip in OnResize() method Pin
Russian Percussion22-May-04 4:13
sussRussian Percussion22-May-04 4:13 
GeneralRe: Determining screen size for resizing grip in OnResize() method Pin
ABOCuk11-May-05 1:52
memberABOCuk11-May-05 1:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180515.1 | Last Updated 23 Feb 2004
Article Copyright 2004 by Zhang Songling
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid