개발자의 사투

C# Devexpress CheckListBoxControl 내용 줄바꿈 본문

컴방/C#

C# Devexpress CheckListBoxControl 내용 줄바꿈

개발자룽 2020. 9. 16. 09:40

CheckListBoxControl.Apperance.TextOptions.WordWrap = Wrap

 

MeasureItem 이벤트 설정

private void checkedListBoxControl1_MeasureItem(object sender, MeasureItemEventArgs e)
{
    DevExpress.XtraEditors.CheckedListBoxControl lb = sender as DevExpress.XtraEditors.CheckedListBoxControl;
    string itemValue = Convert.ToString(lb.Items[e.Index]);
    float i = 0;

    using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1)))
    {
        SizeF size = graphics.MeasureString(itemValue, lb.Font);
        i = size.Width / lb.Size.Width;
    }
    if (i > 0)
    {
        e.ItemHeight = e.ItemHeight * (Convert.ToInt32(i) + 1);
    }
}

 

Comments