我正在使用下面的代碼來重寫和繪製列表框中的每個列表項。如何將邊框添加到ListBox的下拉區域?
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(studentsListBox.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();
的代碼是工作,我會懷疑,但是我還想添加邊框列表框中的整個下拉部分(請參閱下面的示例圖像。)我如何添加邊框整個列表?
你在問兩個問題 - 如何在下拉列表上繪製邊框,以及如何修改列表中每個元素的外觀?請更新您的問題以反映您的問題的性質或詢問兩個單獨的SO問題。謝謝。 – RLH
@RLH我修改了我的問題,你會在這一個幫助.. –