Winform ComboBox如何獨(dú)立繪制下拉選項(xiàng)的字體顏色
眾所周知,cbo1.ForeColor會(huì)同時(shí)改變cbo1.Text和下拉選項(xiàng)字體顏色。
獨(dú)立繪制下拉選項(xiàng)字體顏色,F(xiàn)oreColor 只對(duì) cbo1.Text 顏色有效的辦法,示例:
private void cb7_DrawItem(object sender, DrawItemEventArgs e)
{
DrawCboItems(sender, e);
}
private void cb7_SelectedIndexChanged(object sender, EventArgs e)
{
SetCboTextColor(sender);
}
private void SetCboTextColor(object sender)
{
ComboBox cbx = sender as ComboBox;
if (cbx.Text == "+")
cbx.ForeColor = Color.Red;
else
cbx.ForeColor = Color.Black;
}
private void DrawCboItems(object sender, DrawItemEventArgs e)
{
ComboBox cbo = sender as ComboBox;
//初始化字體和背景色
Pen fColor = new Pen(Color.Black);
Pen bColor = new Pen(Color.White);
switch (e.Index)
{ //下拉選項(xiàng)的索引
case 1:
{
fColor = new Pen(Color.Red);
break;
}
}
e.Graphics.FillRectangle(bColor.Brush, e.Bounds);
e.Graphics.DrawString((string)cbo.Items[e.Index], this.Font, fColor.Brush, e.Bounds);
}
以上就是Winform ComboBox如何獨(dú)立繪制下拉選項(xiàng)的字體顏色的詳細(xì)內(nèi)容,更多關(guān)于Winform ComboBox繪制字體顏色的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Unity實(shí)現(xiàn)毫秒延時(shí)回調(diào)功能
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)毫秒延時(shí)回調(diào)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
C#中DataTable 轉(zhuǎn)換為 Json的方法匯總(三種方法)
JavaScript Object Notation (Json)是一種輕量級(jí)的數(shù)據(jù)交換格式,下面小編給大家介紹三種方法實(shí)現(xiàn)DataTable轉(zhuǎn)換成 Json 對(duì)象,感興趣的朋友一起看看吧2016-11-11
C#實(shí)現(xiàn)泛型動(dòng)態(tài)循環(huán)數(shù)組隊(duì)列的方法
隊(duì)列一種先進(jìn)先出的數(shù)據(jù)結(jié)構(gòu),本文通過(guò)實(shí)例代碼給大家介紹下C#實(shí)現(xiàn)泛型動(dòng)態(tài)循環(huán)數(shù)組隊(duì)列的方法,感興趣的朋友一起看看吧2022-01-01
c#之OpenFileDialog解讀(打開文件對(duì)話框)
這篇文章主要介紹了c#之OpenFileDialog(打開文件對(duì)話框),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07
帶著問(wèn)題讀CLR via C#(筆記二)類型基礎(chǔ)
A1: Object類型共包含6個(gè)方法,Equals, GetHashCode, ToString, GetType, MemberwiseClone和Finalize.2013-04-04
C#編程中使用ref和out關(guān)鍵字來(lái)傳遞數(shù)組對(duì)象的用法
這篇文章主要介紹了C#編程中使用ref和out關(guān)鍵字來(lái)傳遞數(shù)組對(duì)象的用法,在C#中數(shù)組也是對(duì)象可以被傳遞,需要的朋友可以參考下2016-01-01

