在网上找了好久都没有较好的或者代码,都是说自己绘画上去就可以,我还是直接贴图吧
listbox 属性调为OwnerDrawVariable
//listbox内容居
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
StringFormat strFmt = new StringFormat
{
Alignment = StringAlignment.Center, //文本垂直居中
LineAlignment = StringAlignment.Center //文本水平居中
};
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds, strFmt);
}
listbox在form窗体居中
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
int x = (int)(0.5 * (this.Width - listBox1.Width));
int y = listBox1.Location.Y;
listBox1.Location = new Point(x, y);
}