注意: 以下代码,属性直接赋值的语法糖要vs2015以上才支持。
 
 using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace RaywindStudio.Components
{
public class TabCtrlX : TabControl
{
public TabCtrlX()
{
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint, true);//用户自己绘制
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
//让控件支持透明色
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
} #region designer
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
} #endregion
#endregion
//[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public override Color BackColor {
get {
return Color.FromArgb(Alpha, BgColor);
}
set {
Alpha = BackColor.A;
BgColor = BackColor;
}
} [DisplayName("Color.Alpha")]
[CategoryAttribute("Color"), DescriptionAttribute("Opacity不透明度0--255")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public byte Alpha { get; set; } = ; [DisplayName("Color.BgColor")]
[CategoryAttribute("Color"), DescriptionAttribute("TabControl工作区背景色")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public Color BgColor { get; set; } = Color.White; [DisplayName("Color.BordColor")]
[CategoryAttribute("Color"), DescriptionAttribute("TabControl边线颜色")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public Color BordColor { get; set; } = Color.LightGray; [DisplayName("Color.TitleColor")]
[CategoryAttribute("Color"), DescriptionAttribute("TabPage标头背景色")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public Color TitleColor { get; set; } = Color.WhiteSmoke; [DisplayName("Color.TitleSeleColor")]
[CategoryAttribute("Color"), DescriptionAttribute("TabPage标头选中背景色")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public Color TitleSeleColor { get; set; } = Color.White; [DisplayName("Color.TextColor")]
[CategoryAttribute("Color"), DescriptionAttribute("TabPage标题颜色")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public Color TextColor { get; set; } = Color.Gray; [DisplayName("Color.TextSeleColor")]
[CategoryAttribute("Color"), DescriptionAttribute("TabPage选中标题颜色")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public Color TextSeleColor { get; set; } = Color.Black; protected override void OnPaint(PaintEventArgs e)
{
this.DrawTitle(e.Graphics);
base.OnPaint(e);
DrawBorder(e.Graphics);
} protected void DrawBorder(Graphics g)
{
g.DrawRectangle(new Pen(BordColor, 1F), ClientRectangle);
} protected void DrawTitle(Graphics g)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
using (SolidBrush sb = new SolidBrush(SystemColors.Control))
{
for (int i = ; i < this.TabPages.Count; i++)
{
Rectangle rect = this.GetTabRect(i);
if (this.SelectedIndex == i)
{
sb.Color = TitleSeleColor;
g.FillRectangle(sb, rect);
g.DrawString(this.TabPages[i].Text, this.Font, new SolidBrush(TextSeleColor), rect, sf);
}
else
{
sb.Color = TitleColor;
g.FillRectangle(sb, rect);
g.DrawString(this.TabPages[i].Text, this.Font, new SolidBrush(TextColor), rect, sf);
}
}
}
}
}
}

TabCtrlX

 using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms; namespace RaywindStudio.Components
{ public partial class DataGViewX : DataGridView
{
public DataGViewX()
{
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint, true);//用户自己绘制
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
} private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
} [DescriptionAttribute("自定义背景图:当BackTransparent=True时,忽略此设置,直接使用父容器背景")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public Image BackImage { get; set; } [DescriptionAttribute("背景透明:当True时,直接使用父容器背景。否则使用BackImage填充背景")]
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
public bool BackTransparent { get; set; } = true; protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds)
{
base.PaintBackground(graphics, clipBounds, gridBounds);
if(BackTransparent)
BackImage = GetBackImage(this.Parent, this.Left, this.Top, this.Width, this.Height);
if (BackImage != null)
graphics.DrawImage(BackImage, clipBounds);
} public Bitmap GetBackImage(Control parent, int x, int y, int w, int h)
{
if (parent.BackgroundImage != null)
{
Bitmap bt = new Bitmap(parent.Width, parent.Height);
PictureBox pb = new PictureBox();
pb.Size = parent.Size;
pb.BackgroundImage = parent.BackgroundImage;
pb.BackgroundImageLayout = parent.BackgroundImageLayout;
pb.DrawToBitmap(bt, pb.DisplayRectangle);
pb.Dispose();
Bitmap destBitmap = new Bitmap(w, h);
Graphics g = Graphics.FromImage(destBitmap);
g.DrawImage(bt, new Rectangle(, , w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel);
bt.Dispose();
g.Dispose();
return destBitmap;
}
else
return null;
}
} }

DataGViewX

最新文章

  1. hdu 2202 最大三角形 (凸包)
  2. java8中的Stream
  3. 百度地图BMap API实例
  4. poj 2749 Building roads (二分+拆点+2-sat)
  5. Vue爬坑之vuex初识
  6. 一般处理程序获取Session方式
  7. codeforces 895B XK Segments 二分 思维
  8. 第三节:dingo/API 最新版 V2.0 之 Creating API Endpoints (连载)
  9. 【java】字节码操作技术
  10. vue的基本操作
  11. 修改xml成正方形,保存
  12. SSH(Spring+Struts2+Hibernate) of mappings(SSH三大框架的映射问题)
  13. redis 配置命令
  14. system generator学习笔记【02】
  15. SpringMVC之文件上传异常处理
  16. HDFS高级功能
  17. pyspider爬取数据存入es--1.安装驱动
  18. vs 加载 dll 缓慢
  19. oracle和mysql对时间与字符串的转换
  20. Java5的新特性

热门文章

  1. Vue 项目 在局域网内访问
  2. mybatis源码探索笔记-1(构建SqlSessionFactory)
  3. springMVC 的拦截器理解
  4. 树莓派4B踩坑指南 - (10)安装坚果云(更新:暂不支持)
  5. 「NOI2006」最大获利
  6. 一文解读RISC与CISC (转)
  7. 1.ORM介绍,基本配置及通过ORM框架创建表
  8. Python回收机制
  9. LDAP-轻量级目录访问协议(统一认证)
  10. log4j 日志配置