c# winform应用程序listbox各项之间的距离

来源:互联网 发布:淘宝店铺异常无法开店 编辑:程序博客网 时间:2024/05/21 17:13

把DrawMode属性设置为OwnerDrawFixed或OwnerDrawVariable

添加DrawItem事件

                e.DrawBackground();                e.DrawFocusRectangle();                StringFormat strFmt = new System.Drawing.StringFormat();                strFmt.Alignment = StringAlignment.Center; //文本垂直居中                strFmt.LineAlignment = StringAlignment.Center; //文本水平居中                e.Graphics.DrawString(listCategory.Items[e.Index].ToString(), e.Font, new SolidBrush(e.Red), e.Bounds, strFmt);

listbox控件最少一项,否则就会提示错误,也可加一个判空把这种情况解决。

1 0
原创粉丝点击