c#GDI+实现类似油门踏板效果的自定义控件
先看效果图
下面是代码
protected override void OnPaint(PaintEventArgs e) { e.Graphics.SetGDIHigh(); var rect = new Rectangle(0, 0, this.Width, this.Height); // 创建变换矩阵 Matrix transformMatrix = new Matrix(); // 使用平行四边形的方法近似梯形 transformMatrix.Shear(-lidu * 0.3f, 0); // 应用变换 e.Graphics.Transform = transformMatrix; var rectNew = new RectangleF(lidu * 0.3f * this.Width, lidu * 0.3f * this.Height, this.Width, (1 - lidu * 0.3f) * this.Height); e.Graphics.DrawImage(bitCache, rectNew, new Rectangle(0, 0, bitCache.Width, bitCache.Height), GraphicsUnit.Pixel); }
作者:冰封一夏
出处:http://www.cnblogs.com/bfyx/
HZHControls官网:http://www.hzhcontrols.cn
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git