How can I convert a string length to a pixel unit?

前端 未结 5 516
时光取名叫无心
时光取名叫无心 2020-11-30 04:17

I have a string like this:

string s = \"This is my string\";

I am creating a Telerik report and I need to define a textbox tha

5条回答
  •  执念已碎
    2020-11-30 04:31

    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));
    }
    

    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
    

提交回复
热议问题