c#按钮字体.高度不能设置为双值.不能从双精度转换为浮点数
本文关键字:不能 双精度 转换 浮点数 高度 按钮 设置 字体 | 更新日期: 2023-09-27 18:16:56
我有一个名为button1的按钮。使用工具箱,我可以设置按钮字体高度为双值,使用属性,然后字体,然后大小,我可以设置为30.251。但是当我以编程方式设置它时,我不能写30.251。
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double value=90.753/3;//the numerator & denominator came from certain computations
Button button1 = new Button();
button1.Font = new Font("Arial", value, FontStyle.Bold);
}
}
}
有什么问题吗?我需要一个精确的字体高度值,精确到小数点后3位。它显示了一个错误"Can't convert from double to float"
字号为float,非double试一试:
button1.Font = new Font("Arial", 30.251f, FontStyle.Bold);
或者如果值是双属性则使用:
button1.Font = new Font("Arial", (float)fontSize, FontStyle.Bold);
或者如果你想早点得到号码
float value=(float)(90.753/3);//the numerator & denominator came from certain computations
或更干净
float value=90.753f/3;//the numerator & denominator came from certain computations