1

我有一个面板,默认情况下我将一个字符串拧成一个矩形正在绘制可以适应剩余空间,或者我需要从新行开始我正在计算剩余空间,如下所示。但它不能将浮点数转换为 sizeF。

foreach (btnObject custItem in this.lstAcceptedCustomizatio)
{
    System.Drawing.SizeF newString = g.MeasureString(custItem.BtnName + ", ", this.Font); //get the size of the text property
    System.Drawing.SizeF drawnString = g.MeasureString(basketItemDescription, this.Font); //get the size of the text property
    if(newString.Width> (this.Width-drawnString)) //THIS LINE DO NOT WORK
        basketItemDescription = basketItemDescription + custItem.BtnName + ", ";
}
4

2 回答 2

2
if(newString.Width> this.Width-drawnString.Width) ....
于 2013-09-07T14:06:16.460 回答
1

控件在内部使用整数值,并且大小和位置不能设置为浮点数。

SizeF has a ToSize method

Size size = sizeF.ToSize();

or

myControl.Size = sizeF.ToSize();
于 2013-09-07T14:57:29.407 回答