ComboBox
의 DrawMode
을 OwnerDrawFixed
으로 변경하면 다음을 사용할 수 있습니다. 헤더와 항목을 그리는 DrawItem
이벤트. 그러나 사용자가 헤더 항목을 선택하지 못하도록 할 수있는 방법은 없습니다.
private List<string> groupItems = new List<string>();
private void Form1_Load(object sender, EventArgs e)
{
groupItems.Add("Great Bands");
groupItems.Add("Great Bandages");
comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
comboBox1.Items.Add("Great Bands");
comboBox1.Items.Add("Led Zeppelin");
comboBox1.Items.Add("Steppenwolf");
comboBox1.Items.Add("Great Bandages");
comboBox1.Items.Add("Band-Aid");
comboBox1.Items.Add("Curad");
}
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if (e.Index > -1)
{
string drawText = comboBox1.Items[e.Index].ToString();
if (groupItems.Contains(drawText))
{
using (Font font = new Font(comboBox1.Font, FontStyle.Bold))
e.Graphics.DrawString(drawText, font, Brushes.Black, e.Bounds);
}
else
e.Graphics.DrawString(drawText, comboBox1.Font, Brushes.Black, new Rectangle(16, e.Bounds.Top, e.Bounds.Width - 16, e.Bounds.Height));
e.DrawFocusRectangle();
}
}
어떤 UI 기술이 필요합니까? Windows Forms, WebForms, WPF, Silverlight? – Jehof
죄송합니다 .. WinForms에서 필요합니다. – flipis