listbox 表头自动换行_c# listbox 自动换行

//自定义控件, 然后在工具箱拖过来用 再把BackColor 设置为Transparentpublic partial class TransparentListBox : ListBox { public TransparentListBox() { this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); } protected override void OnSelectedIndexChanged(EventArgs e) { this.Invalidate(); base.OnSelectedIndexChanged(e); } protected override void OnPaint(PaintEventArgs e) { if (this.Focused && this.SelectedItem != null) { Rectangle itemRect = this.GetItemRectangle(this.SelectedIndex); e.Graphics.FillRectangle(Brushes.Green, itemRect); } for (int i = 0; i < Items.Count; i++) { e.Graphics.DrawString(this.GetItemText(Items[i]), this.Font, new SolidBrush(this.ForeColor), this.GetItemRectangle(i)); } base.OnPaint(e); } }

取消

评论

你可能感兴趣的:(listbox,表头自动换行)