c#GDI+实现类似油门踏板效果的自定义控件

先看效果图

GIF.gif

下面是代码

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);
}

 

posted @ 2025-02-20 09:11  冰封一夏  阅读(64)  评论(0)    收藏  举报
HZHControls控件库官网:https://www.hzhcontrols.cn