Tag: ondrawitem

覆盖ListBox的DrawItem – 未重绘未选择的项目

这是一个C#桌面应用程序。 我的ListBox的DrawStyle属性设置为OwnerDrawFixed 。 问题:我重写DrawItem以不同的字体绘制文本,它的工作原理。 但是当我开始在运行时调整窗体大小时,所选项目被正确绘制,但其余部分没有重绘,导致文本看起来对于未选择的项目是损坏的。 这是我的代码: private void listDevices_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); string textDevice = ((ListBox)sender).Items[e.Index].ToString(); e.Graphics.DrawString(textDevice, new Font(“Ariel”, 15, FontStyle.Bold), new SolidBrush(Color.Black), e.Bounds, StringFormat.GenericDefault); // Figure out where to draw IP StringFormat copy = new StringFormat( StringFormatFlags.NoWrap | StringFormatFlags.MeasureTrailingSpaces ); copy.SetMeasurableCharacterRanges(new CharacterRange[] {new CharacterRange(0, textDevice.Length)}); Region[] regions = e.Graphics.MeasureCharacterRanges( textDevice, new Font(“Ariel”, […]