如何将float转换为size?

时间:2013-09-07 13:59:50

标签: c#

我有一个面板我默认将一个字符串拧到一个矩形我已经设置了面板300的宽度,我设置为float类型的变量,我拧了一些字符串,但我想识别正在绘制的下一个项目可以适应剩余空间,或者我需要从新行启动​​它我正在计算剩余空间,如下所示。 但它不能将float转换为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 + ", ";
}

2 个答案:

答案 0 :(得分:2)

if(newString.Width> this.Width-drawnString.Width) ....

答案 1 :(得分:1)

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

SizeF has a ToSize method

Size size = sizeF.ToSize();

or

myControl.Size = sizeF.ToSize();
相关问题