c# - 我无法对标准按钮进行正常舍入
问题描述
我试图进行正常的四舍五入。而且我无法平滑按钮本身的舍入。第二个问题,如何使按钮四舍五入,以使 BackgroundImage 中使用的照片不会四舍五入???
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Test_Project.SupportClass
{
public class Buttom_Class4 : Button
{
public Buttom_Class4()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.ResizeRedraw, true);
}
private int radius = 20;
[DefaultValue(20)]
public int Radius
{
get { return radius; }
set
{
radius = value;
this.RecreateRegion();
}
}
private GraphicsPath GetRoundRectagle(Rectangle bounds, int radius)
{
GraphicsPath path = new GraphicsPath();
path.AddArc(bounds.X, bounds.Y, radius, radius, 180, 90);
path.AddArc(bounds.X + bounds.Width - radius, bounds.Y, radius, radius, 270, 90);
path.AddArc(bounds.X + bounds.Width - radius, bounds.Y + bounds.Height - radius,
radius, radius, 0, 90);
path.AddArc(bounds.X, bounds.Y + bounds.Height - radius, radius, radius, 90, 90);
path.CloseAllFigures();
return path;
}
private void RecreateRegion()
{
var bounds = ClientRectangle;
bounds.Width--; bounds.Height--;
using (var path = GetRoundRectagle(bounds, this.Radius))
this.Region = new Region(path);
this.Invalidate();
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
this.RecreateRegion();
}
}
}
解决方案
推荐阅读
- javascript - 检查数组是否包含两个特定值
- sql - Solr4.10.3中的值如何求和
- c++ - 如何在 Qt 中获取字符串的一部分?
- ios - 如何在 10 个按钮中快速创建 1 个带有颜色的微光渐变
- javascript - 如何在JavaScript中将数字从字符串转换为带有以下零的浮点数?
- c# - 将动画添加到具有不同 scriptableObjects 数据的单个预制件?
- c++ - cv::UMat 的 m2=(m1==v) 的有效替换?
- caching - turducken 模式的公共缓存 - 如何在 GWT 模块之间共享数据
- ios - 斯威夫特:如何理解下载的图像是空的?
- wix - WiX CloseApplication - 使用系统托盘图标关闭应用程序 - 仍然存在问题