本文介绍了我怎么能转换成字符串长度像素单元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的字符串:
I have a string like this:
string s = "This is my string";
我创建一个Telerik的报告,我需要定义一个文本
这是我的字符串的宽度。然而,大小属性需要被设置为一个单元(像素,点,英寸等)。我如何转换我的字符串长度进,说像素,所以我可以设置宽度?
I am creating a Telerik report and I need to define a textbox
that is the width of my string. However the size property needs to be set to a Unit (Pixel, Point, Inch, etc). How can I convert my string length into, say a Pixel so I can set the width?
编辑:我试图获得对图形对象的引用,但是这是在从 Telerik.Reporting.Report 。
I have tried getting a reference to the graphics object, but this is done in a class that inherits from
Telerik.Reporting.Report
.
推荐答案
如果不使用控件或窗体的:
Without using of a control or form:
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1)))
{
SizeF size = graphics.MeasureString("Hello there", new Font("Segoe UI", 11, FontStyle.Regular, GraphicsUnit.Point));
}
或者在VB.Net:
Or in VB.Net:
Using graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(New Bitmap(1, 1))
Dim size As SizeF = graphics.MeasureString("Hello there", New Font("Segoe UI", 11, FontStyle.Regular, GraphicsUnit.Point))
End Using
这篇关于我怎么能转换成字符串长度像素单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!