473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with Painting ListBox

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
Jul 22 '06 #1
1 2443
Ignore the Comments (//) i was trying something and fogot to take them out.

"DigitalMythic" wrote:
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
Jul 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the...
3
by: Shravan Kumar | last post by:
Hi, I am using my code to set column widths of datagrid columns dynamically, but when I am setting the column widths to zero, the header text of the column whose width is made to zero is...
2
by: CMEDIA_SOUND | last post by:
I have a peculiar problem, I have a tabpage with a label control on it. When i set a background image to the tabpage and drag the label around it has paint issues in that it is slow, granted the...
2
by: Joep | last post by:
L.S., I am using the picture box's paint event to load an image if not yet loaded. The picture box is one of many that together occupy the area of a panel. Not all boxes are visible so not all...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
2
by: tangokilo | last post by:
Hello and thanks for your help, I have the following Listbox created in VisualStudio 2003 designer, desiring to select multiple entries from that list: -------------------------------...
2
by: osmarjunior | last post by:
Hello there... I have a custom user control, in which i put a panel on the top. In the Paint event of the panel, i have the following code: VisualStyleRenderer x = new...
1
by: =?Utf-8?B?RmxvcmlhbiBLb3dhbHNreQ==?= | last post by:
I need to paint a rectangle in above the textbox of a combobox. How can i do that. At present the rectangle is always in the background and the textbox is in the foreground!! Thanks
1
by: TN | last post by:
I forget how to fix this.. But whenever I draw to the ListBox with DrawItem, it flickers. Double Buffering etc. do not work. I remember fixing this once and I had to use some Windows API...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.