zoukankan      html  css  js  c++  java
  • c# 自动计算字符串的宽度

    测试代码:

    string str = "字符串";
    var width = TextRenderer.MeasureText(str, this.Font);
    var width2 = this.CreateGraphics().MeasureString(str, this.Font);

    str = "字符串"时,结果为:

    {Width=41, Height=12}

    width2:{Width=41.06836, Height=15.1875}

    AutoSize = true的Label尺寸为41, 12

    str = "zifuchuan"时,结果为:

    {Width=59, Height=12}

    width2:{Width=59.68748, Height=13.5}

    AutoSize = true的Label尺寸为59, 12

    综合上述的结果,我取用TextRenderer.MeasureText作为最终获取字符串像素宽度的方法。

  • 相关阅读:
    关于表单的jQuery练习
    jQuery中的综合动画
    jQuery中自定义简单动画的实现
    清除浮动
    定位
    盒子模型
    笔记
    笔记
    翻页
    DOM
  • 原文地址:https://www.cnblogs.com/icyJ/p/MeasureText.html
Copyright © 2011-2022 走看看