0
我有一个项目列表框更改列表框的项目里面的项目fontstyle ....如何使用C#和WinForms
say Listboxitem1
listboxitem2
listboxitem3...
是否有可能改变listboxitem1的项目风格。
我已经看到这个代码改变列表框的选择项目的背景颜色,但我力求找到任何解决方案,以改变listboxitem的项目样式....
以下代码是用于更改列表中选定项目的背景颜色框。但我发现不力的任何属性改变项目风格(如字体)
if (e.Index < 0) return;
// if the item state is selected then change the back color
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
e = new DrawItemEventArgs(e.Graphics,
e.Font,
e.Bounds,
e.Index,
e.State^DrawItemState.Selected,
e.ForeColor,
Color.Red); // Choose the color
// Draw the background of the ListBox control for each item.
e.DrawBackground();
// Draw the current item text
e.Graphics.DrawString(listbox1.Items[e.Index].ToString(), e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
// If the ListBox has focus, draw a focus rectangle around the selected item.
e.DrawFocusRectangle();
可以在任何一个有这个想法..
非常感谢..
我试图像到位e.font的这个“fontstyle.bold”,但它不工作....使用这一个,你可以更改字体样式唯一入选的项目不所有项目.....有没有其他选项..... –
看 - 我看不到这个代码的位置,但我想它是在该项目的用户提取权?如果是,那么你可以照我说的去做。只需在e.Graphics.DrawString代码中使用“Font”而不是Fontstyle来代替e.Font即可。你必须提供像'新字体(e.Font,FontStyle.Bold)' – Carsten
你的意思是,我需要改变这一行.... e.Graphics.DrawString(listbox1.Items [e.Index]。 ToString(),e.Font,Brushes.Black,e.Bounds,StringFormat.GenericDefault); –