I want some way to make a given word bold(the first two characters of each item in a listbox), and nothing else, something like this:
01 car
02 house
03 market
As for these three, being items in a listbox control, ALWAYS the first two characters, the rest should not be bold.
Is there any practical way for doing so ?
Data:
- Visual Studio 2008
- .NET 3.5
request:
private void lstMaster_DrawItem(object sender, DrawItemEventArgs e)
{
//TEST
e.DrawBackground();
Brush myBrush = Brushes.Black;
Pen pen = new Pen(myBrush);
e.Graphics.DrawRectangle(pen, 0, 0, 10, 10); //BREAKPOINT HERE
e.Graphics.DrawString("aaa" + lstMaster.Items[e.Index].ToString(),
e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
e.DrawFocusRectangle();
}
It just keept the same, no rectangle, no “AAA”, or square no breakpoint reached…
It is possible, You will need to use the listbox’s DrawItem event and from there you can draw your items however you would like to:
DrawItem event on MSDN
Here is an example that draws each item with different color:
According to the documentation you will also need to change the DrawMode property of the listbox in order the fire the event: