Problem with Painting ListBox

G

Guest

Just to set the scene, I have a listbox in an application which im working
on. The List box will have owner drawn items in it when it has items. To
start with the listbox is empty. What Im trying to do is have it so that
when the listbox is empty, the background is gradient filled with a message
for the user in the middle.

See code below:

if (lstRecoveryItems.Items.Count == 0)
//{
// Create a local copy of the Graphics object
Graphics gfxItems = e.Graphics;

// The guidance message to draw out if no items are present
// string strIntroduction = "User Information Message.";

// Get a measurment of the String so the drawn text can be
centred
//SizeF fnSize = gfxItems.MeasureString(strIntroduction, new
Font("Verdana", 8));

// Create a Floating point location for where to draw the
string
// PointF ptLocation = new PointF();

// Work out the location for the exact centre of the text
// ptLocation.X = ((float)lstItems.Width - fnSize.Width) / 2;
// ptLocation.Y = ((float)lstItems.Height - fnSize.Height) / 2;

// Create a Linear Brush to help Gradient the back drop of
the control
// Color from White to Control Grey
LinearGradientBrush linBsh = new
LinearGradientBrush(e.Bounds, Color.White, Color.LightGray, 0f);

// Fill the Gradient background into the control
gfxItems.FillRectangle(linBsh, gfxItems.ClipBounds);

// Draw the text out to the control
// gfxItems.DrawString(strIntroduction, new Font("Verdana",
8), new SolidBrush(Color.Black), ptLocation);
}
else
{
// Implement code to draw items when a collection exists
// TODO : Code to draw list items
}

This code does exactly what I need however, if I have a dialog open in my
application i.e. a Confirm MEssageBox, the background isnt redrawing its
simply going white until the dialog is dismissed at which point it redraws.

Any ideas on whether this code is wrong/how to ensure my background and text
is drawn even when another window is moved over it.

Regards

DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top