日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# WinForm 自定义控件,DataGridView背景透明,TabControl背景透明

發布時間:2025/3/21 C# 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# WinForm 自定义控件,DataGridView背景透明,TabControl背景透明 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注意: 以下代碼,屬性直接賦值的語法糖要vs2015以上才支持。 1 using System.ComponentModel; 2 using System.Drawing; 3 using System.Windows.Forms; 4 namespace RaywindStudio.Components 5 { 6 public class TabCtrlX : TabControl 7 { 8 public TabCtrlX() 9 { 10 InitializeComponent(); 11 this.SetStyle(ControlStyles.UserPaint, true);//用戶自己繪制 12 this.SetStyle(ControlStyles.ResizeRedraw, true); 13 this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); 14 this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); 15 //讓控件支持透明色 16 this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); 17 } 18 19 #region designer 20 /// <summary> 21 /// 必需的設計器變量。 22 /// </summary> 23 private System.ComponentModel.IContainer components = null; 24 25 /// <summary> 26 /// 清理所有正在使用的資源。 27 /// </summary> 28 /// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param> 29 protected override void Dispose(bool disposing) 30 { 31 if (disposing && (components != null)) 32 { 33 components.Dispose(); 34 } 35 base.Dispose(disposing); 36 } 37 38 #region 組件設計器生成的代碼 39 40 /// <summary> 41 /// 設計器支持所需的方法 - 不要 42 /// 使用代碼編輯器修改此方法的內容。 43 /// </summary> 44 private void InitializeComponent() 45 { 46 components = new System.ComponentModel.Container(); 47 } 48 49 #endregion 50 #endregion 51 //[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 52 public override Color BackColor { 53 get { 54 return Color.FromArgb(Alpha, BgColor); 55 } 56 set { 57 Alpha = BackColor.A; 58 BgColor = BackColor; 59 } 60 } 61 62 [DisplayName("Color.Alpha")] 63 [CategoryAttribute("Color"), DescriptionAttribute("Opacity不透明度0--255")] 64 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 65 public byte Alpha { get; set; } = 16; 66 67 [DisplayName("Color.BgColor")] 68 [CategoryAttribute("Color"), DescriptionAttribute("TabControl工作區背景色")] 69 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 70 public Color BgColor { get; set; } = Color.White; 71 72 [DisplayName("Color.BordColor")] 73 [CategoryAttribute("Color"), DescriptionAttribute("TabControl邊線顏色")] 74 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 75 public Color BordColor { get; set; } = Color.LightGray; 76 77 [DisplayName("Color.TitleColor")] 78 [CategoryAttribute("Color"), DescriptionAttribute("TabPage標頭背景色")] 79 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 80 public Color TitleColor { get; set; } = Color.WhiteSmoke; 81 82 [DisplayName("Color.TitleSeleColor")] 83 [CategoryAttribute("Color"), DescriptionAttribute("TabPage標頭選中背景色")] 84 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 85 public Color TitleSeleColor { get; set; } = Color.White; 86 87 [DisplayName("Color.TextColor")] 88 [CategoryAttribute("Color"), DescriptionAttribute("TabPage標題顏色")] 89 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 90 public Color TextColor { get; set; } = Color.Gray; 91 92 [DisplayName("Color.TextSeleColor")] 93 [CategoryAttribute("Color"), DescriptionAttribute("TabPage選中標題顏色")] 94 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 95 public Color TextSeleColor { get; set; } = Color.Black; 96 97 protected override void OnPaint(PaintEventArgs e) 98 { 99 this.DrawTitle(e.Graphics); 100 base.OnPaint(e); 101 DrawBorder(e.Graphics); 102 } 103 104 protected void DrawBorder(Graphics g) 105 { 106 g.DrawRectangle(new Pen(BordColor, 1F), ClientRectangle); 107 } 108 109 protected void DrawTitle(Graphics g) 110 { 111 StringFormat sf = new StringFormat(); 112 sf.Alignment = StringAlignment.Center; 113 sf.LineAlignment = StringAlignment.Center; 114 using (SolidBrush sb = new SolidBrush(SystemColors.Control)) 115 { 116 for (int i = 0; i < this.TabPages.Count; i++) 117 { 118 Rectangle rect = this.GetTabRect(i); 119 if (this.SelectedIndex == i) 120 { 121 sb.Color = TitleSeleColor; 122 g.FillRectangle(sb, rect); 123 g.DrawString(this.TabPages[i].Text, this.Font, new SolidBrush(TextSeleColor), rect, sf); 124 } 125 else 126 { 127 sb.Color = TitleColor; 128 g.FillRectangle(sb, rect); 129 g.DrawString(this.TabPages[i].Text, this.Font, new SolidBrush(TextColor), rect, sf); 130 } 131 } 132 } 133 } 134 } 135 } TabCtrlX

?

1 using System.ComponentModel; 2 using System.Drawing; 3 using System.Windows.Forms; 4 5 namespace RaywindStudio.Components 6 { 7 8 public partial class DataGViewX : DataGridView 9 { 10 public DataGViewX() 11 { 12 InitializeComponent(); 13 this.SetStyle(ControlStyles.UserPaint, true);//用戶自己繪制 14 this.SetStyle(ControlStyles.ResizeRedraw, true); 15 this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); 16 this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); 17 this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); 18 } 19 20 private System.ComponentModel.IContainer components = null; 21 protected override void Dispose(bool disposing) 22 { 23 if (disposing && (components != null)) 24 { 25 components.Dispose(); 26 } 27 base.Dispose(disposing); 28 } 29 private void InitializeComponent() 30 { 31 components = new System.ComponentModel.Container(); 32 } 33 34 [DescriptionAttribute("自定義背景圖:當BackTransparent=True時,忽略此設置,直接使用父容器背景")] 35 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 36 public Image BackImage { get; set; } 37 38 [DescriptionAttribute("背景透明:當True時,直接使用父容器背景。否則使用BackImage填充背景")] 39 [EditorBrowsable(EditorBrowsableState.Always), Browsable(true)] 40 public bool BackTransparent { get; set; } = true; 41 42 protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds) 43 { 44 base.PaintBackground(graphics, clipBounds, gridBounds); 45 if(BackTransparent) 46 BackImage = GetBackImage(this.Parent, this.Left, this.Top, this.Width, this.Height); 47 if (BackImage != null) 48 graphics.DrawImage(BackImage, clipBounds); 49 } 50 51 public Bitmap GetBackImage(Control parent, int x, int y, int w, int h) 52 { 53 if (parent.BackgroundImage != null) 54 { 55 Bitmap bt = new Bitmap(parent.Width, parent.Height); 56 PictureBox pb = new PictureBox(); 57 pb.Size = parent.Size; 58 pb.BackgroundImage = parent.BackgroundImage; 59 pb.BackgroundImageLayout = parent.BackgroundImageLayout; 60 pb.DrawToBitmap(bt, pb.DisplayRectangle); 61 pb.Dispose(); 62 Bitmap destBitmap = new Bitmap(w, h); 63 Graphics g = Graphics.FromImage(destBitmap); 64 g.DrawImage(bt, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel); 65 bt.Dispose(); 66 g.Dispose(); 67 return destBitmap; 68 } 69 else 70 return null; 71 } 72 } 73 74 } DataGViewX

?

轉載于:https://www.cnblogs.com/leavind/p/6732530.html

總結

以上是生活随笔為你收集整理的C# WinForm 自定义控件,DataGridView背景透明,TabControl背景透明的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 黄色性大片 | 成人免费观看在线视频 | jizzjizz黄大片| 深夜影院深a | 国产农村妇女精品 | 国产日韩在线视频 | 极品淫少妇 | 精品国产乱码久久久久久闺蜜 | 五月天精品在线 | 国产又大又黄又爽 | 天堂在线中文网 | kk视频在线观看 | 狠狠操影视 | 男生草女生的视频 | 三上悠亚激情av一区二区三区 | 国产精品一品二区三区的使用体验 | 青春草视频在线免费观看 | 九九在线免费视频 | 午夜婷婷丁香 | 尤物国产在线 | 欧美成人中文字幕 | 九九在线观看高清免费 | 午夜日韩电影 | 国产精品a级 | 精品国产不卡 | 日韩性生活大片 | 看黄色一级视频 | 午夜激情福利视频 | 一区二区精品在线 | 男人的天堂视频 | 好看的黄色录像 | 波多野结衣视频网址 | 欧美日韩在线免费看 | 六月激情综合网 | 热99视频| 国产精品熟女久久久久久 | 波多野42部无码喷潮 | 超碰97在线免费观看 | 国产又粗又长又黄视频 | av老司机久久 | 性猛交xxxx乱大交孕妇印度 | 久久无码专区国产精品s | 久草福利资源在线观看 | 国产精品腿扒开做爽爽爽挤奶网站 | 久操视频在线免费观看 | 狂野欧美性猛交xxxxhd | 超碰精品| 在线免费观看亚洲视频 | 国产欧美精品一区二区三区 | 亚洲国产一二三区 | 欧美大波大乳巨大乳 | 噜噜在线视频 | 免费男女乱淫真视频免费播放 | 国产精品有码 | 动漫毛片| 亚洲成人视屏 | jzzijzzij亚洲成熟少妇在线观看 久久久精品人妻一区二区三区 | 成人黄性视频 | 日本毛片在线观看 | 淫综合网 | 天天色天天草 | 无码aⅴ精品一区二区三区浪潮 | 欧美图片自拍偷拍 | 毛片在线免费视频 | 91在线视频在线观看 | 成人午夜精品福利 | 九九色播 | 乌克兰av在线 | 奇米影 | 国产91精品久久久久久久网曝门 | 一级全黄裸体免费视频 | 午夜一二三区 | 日韩网站在线播放 | 成年人av在线播放 | 国产精品18久久久 | 秋霞啪啪片| 亚洲色偷偷综合亚洲av伊人 | 国产十八熟妇av成人一区 | 国产麻豆久久 | a国产精品 | 亚洲欧美色图在线 | 亚洲最大网站 | 精品网站999www | 国产精品老熟女视频一区二区 | 国产高清不卡av | 一区二区国产在线 | 999超碰 | 落日余晖 | 欧美视频在线观看视频 | 奇米影视第四色888 免费观看a毛片 | 88av.com| 久久九九国产精品 | 一级片免费看视频 | av国产一区二区 | 天天天干干干 | 亚洲欧美婷婷 | 青青青视频免费观看 | 日本欧美久久久久免费播放网 | 欧美成人精品欧美一级乱 |