728x90
ComboxBox의 값을 가운데 정렬 하기 위해서는
DrawItem 이벤트를 생성 후 사용 해야 합니다
우선 속성 값 중 DrawMode 값을 OwnerDrawVariable 값으로 변경합니다
이후 DrawItem 이벤트를 생성 후 이벤트에 아래와 같이 코드를 작성합니다
private void comboBox_DrawItem(object sender, DrawItemEventArgs e)
{
ComboBox cbx = sender as ComboBox;
if (cbx != null)
{
e.DrawBackground();
if (e.Index >= 0)
{
StringFormat sf = new StringFormat();
Brush brush = new SolidBrush(cbx.ForeColor);
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
brush = SystemBrushes.HighlightText;
}
e.Graphics.DrawString(cbx.Items[e.Index].ToString(), cbx.Font, brush, e.Bounds, sf);
}
}
}
제 글이 도움이 되셨다면 댓글 & 공감 부탁드려요 😀
728x90
반응형
'Application > C# (WinForm)' 카테고리의 다른 글
[C# WinForm] 프로세스 리스트 가져오기 (0) | 2023.11.27 |
---|---|
[C# WinForm] MainForm Hide (자기 자신 숨기기) (0) | 2023.11.22 |
[C# WinForm] Panel DoubleBuffered 설정 (0) | 2023.08.21 |
[C# WinForm] QRCode 만들기 (zxing.dll) (0) | 2023.08.02 |
[C# WinForm] Form 반 투명하게 만들기 (컨트롤 미 적용) (0) | 2023.07.24 |