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

本文介绍如何在C# WinForm应用中实现DataGridView和TabControl背景透明的效果,详细探讨了自定义控件透明化的步骤和技术要点。
摘要由CSDN通过智能技术生成

 注意: 以下代码,属性直接赋值的语法糖要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         ///</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值