[C#] CheckedListBox Item 별로 색깔 다르게 하기
아이템별로 색깔 좀 다르게 할라 했더니 구글이가 모르는 척-_-;;;
그래도 결국 찾아서 약간(?) 다듬해서 만듬~ 에이~~ 시간아까워
예제 코드
public partial class ColorCheckedListBox : CheckedListBox
{
Color[] m_crForeColor;
public ColorCheckedListBox()
{
InitializeComponent();
for (int i = 0; i < 7; i++)
{
this.Items.Add(i + "번째 아이템");
}
MakeForeColor();
}
public void MakeForeColor()
{
m_crForeColor = new Color[Items.Count];
Random r = new Random();
for (int i = 0; i < Items.Count; i++)
{
int R = r.Next(0, 256);
int G = r.Next(0, 256);
int B = r.Next(0, 256);
m_crForeColor[i] = Color.FromArgb(R, G, B);
}
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (m_crForeColor.Length <= e.Index)
{
base.OnDrawItem(e);
return;
}
DrawItemEventArgs e2 =
new DrawItemEventArgs(
e.Graphics, e.Font, new Rectangle(e.Bounds.Location, e.Bounds.Size),
e.Index, e.State, m_crForeColor[e.Index],
e.BackColor);
base.OnDrawItem(e2);
}
}
'프로그래밍' 카테고리의 다른 글
Asp.net을 위한 IIS7 초기 설정하기 (Win7) (0) | 2011.04.01 |
---|---|
[오라클] Top 1구문 사용하기 MSSQL 오라클 (2) | 2011.03.22 |
[C#] CheckedListBox Check된것만 Color 변경 (0) | 2011.03.16 |
Oracle과 MSSQL 데이터타입 비교/매치/차이/치환 (0) | 2011.03.16 |
Visual Studio 2010 사용자 환경 초기화 (0) | 2011.03.10 |
댓글