using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;

namespace NewsWebApp.Biz
{
   
 
    public  class TextCount
    {
        System.Drawing.Font gdiFont;
        System.Drawing.Graphics graphics;
        public Font Font
        {
            get { return this.font; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                if (this.font != value)
                {
                    this.font = value;
                    this.gdiFont = null;
                }
            }
        }
        Font font;
 
       /// <summary>
       /// 通过宽度测量文本高度
       /// </summary>
       /// <param name="text">文本</param>
       /// <param name="Textwidth">文本高度</param>
       /// <returns></returns>
        public  float GetHeightByText(string text, int Textwidth)
        {
            Graphics g = Realize();
            Font stringFont = new Font("Arial", 16);
            StringFormat newStringFormat = new StringFormat();
            newStringFormat.FormatFlags = StringFormatFlags.LineLimit;
            // Measure string.
            SizeF stringSize = new SizeF();
            stringSize = g.MeasureString(text, stringFont, Textwidth, newStringFormat);
            return stringSize.Height;
        }

Graphics Realize()
        {
            if (this.graphics == null)
                this.graphics = Graphics.FromHwnd(IntPtr.Zero);
            this.graphics.PageUnit = GraphicsUnit.Point;
           
            return this.graphics;
        }

}
}

 

MeasureString 通过文本宽度获取绘制高度的更多相关文章

  1. css 垂直居中,指定文本宽度换行,指定高度出滚动条

    !DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"&g ...

  2. js 获取浏览器高度和宽度值(多浏览器)(转)

    IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...

  3. JavaScript获取浏览器高度和宽度值(documentElement,clientHeight,offsetHeight,scrollHeight,scrollTop,offsetParent,offsetY,innerHeight)

    IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...

  4. JavaScript获取浏览器高度和宽度值

    IE中:  document.body.clientWidth ==> *DY对象宽度 document.body.clientHeight ==> *DY对象高度 document.do ...

  5. 转:JS获取浏览器高度和宽度

    发现一篇好文章,汇总到自己的网站上. IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> ...

  6. js 获取浏览器高度和宽度值(多浏览器)

    IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...

  7. 不同浏览器JS获取浏览器高度和宽度

    摘自:http://blog.csdn.net/lai_gb/archive/2009/07/04/4320956.aspx IE中: document.body.clientWidth ==> ...

  8. js获取浏览器高度和宽度值,尽量的考虑了多浏览器。

    js获取浏览器高度和宽度值,尽量的考虑了多浏览器. IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ...

  9. 关于JS中获取浏览器高度和宽度值的多种方法(多浏览器)

    三种浏览器获取值方法 IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 ...

随机推荐

  1. LCT学习笔记

    最近自学了一下LCT(Link-Cut-Tree),参考了Saramanda及Yang_Zhe等众多大神的论文博客,对LCT有了一个初步的认识,LCT是一种动态树,可以处理动态问题的算法.对于树分治中 ...

  2. 富文本编辑器CKEditor的使用

    由于最近在架构一个pc端b/s结构的项目,项目中有个论坛模块,当用户发帖时,需要用到富文本编辑器,考虑了一下,决定使用CKEditor富文本编辑器,虽然现在问世的富文本编辑器很丰富,比如还有百度的UE ...

  3. java泛型使用总结

    1. 泛型方法: 2. 泛型类: 3. 通配符. 1.泛型方法 泛型方法在调用时可以接收不同类型的参数.根据传递给泛型方法的参数类型,编译器适当地处理每一个方法调用. 下面是定义泛型方法的规则: 所有 ...

  4. Linux用户角色划分

    在Linux系统中,用户是分角色的,角色不同,对应权限不同.用户角色通过UID和GID识别. 大致分为三种:超级用户,普通用户,虚拟用户. 超级用户:默认是root用户,其UID和GID都是0.roo ...

  5. angular添加,查找与全部删除

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  6. 【学习】滚动延迟加载插件scrollLoading用法

    今天遇到一个很好用的滚动延迟加载的插件,作者是我的偶象大神张鑫旭,其博客为http://www.zhangxinxu.com/. 以前也写过这种效果,用的是lazyload,不过只能实现图片的加载.而 ...

  7. 面试题:使用LinkedList来模拟一个堆栈或者队列数据结构

    请使用LinkedList来模拟一个堆栈或者队列数据结构. 堆栈:先进后出 First In Last Out  (FILO) 队列:先进先出 First In First Out  (FIFO) 我 ...

  8. Java继承--子父类中的构造函数

    子父类中的构造函数的特点: 1.在子类构造对象时,发现,访问子类构造函数时,父类构造函数也运行了.   原因是:在子类的构造函数中第一行有一个默认的隐式语句. super(); 类似于this(); ...

  9. Javascript之pixi框架学习

    pixi 创建渲染器(renderer) 创建一个可以播放动画的区域,相当于(canvas). var renderer = PIXI.autoDetectRenderer(512, 512); do ...

  10. C语言第一次实验报告————PTA实验1.2.3内容

    一.PTA实验作业 题目1.温度转换 本题要求编写程序,计算华氏温度100°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代 ...