效果圖

public class MyCheckedListBox : CheckedListBox { //普通字體 static Font Font1 = new Font(new FontFamily("宋體"), 12, FontStyle.Regular); //中間有橫線 static Font Font2 = new Font(new FontFamily("宋體"), 12, FontStyle.Strikeout); protected override void OnDrawItem(DrawItemEventArgs e) { this.Font = Font1; //選中 if (this.CheckedIndices.Contains(e.Index)) { //文本 this.Font = Font2;//這里設定每個item的字體 ,過去的某個類似的經驗,讓我想到這一點 } DrawItemEventArgs e2 = new DrawItemEventArgs( e.Graphics, Font,//這里設定字體沒有效果,猜測繪制用的 this.Font 而不是這里的 new Rectangle(e.Bounds.Location, e.Bounds.Size), e.Index, (e.State & DrawItemState.Focus) == DrawItemState.Focus ? DrawItemState.Focus : DrawItemState.None, this.ForeColor, //這里可以設定字體顏色 this.BackColor); base.OnDrawItem(e2); } protected override void OnFontChanged(EventArgs e) { //base.OnFontChanged(e);//不注釋會不停閃爍 } }
文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿文字少不能投稿
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/423514.html
標籤:WinForm
