MeasureString 通过文本宽度获取绘制高度
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 通过文本宽度获取绘制高度的更多相关文章
- css 垂直居中,指定文本宽度换行,指定高度出滚动条
!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"&g ...
- js 获取浏览器高度和宽度值(多浏览器)(转)
IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...
- JavaScript获取浏览器高度和宽度值(documentElement,clientHeight,offsetHeight,scrollHeight,scrollTop,offsetParent,offsetY,innerHeight)
IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...
- JavaScript获取浏览器高度和宽度值
IE中: document.body.clientWidth ==> *DY对象宽度 document.body.clientHeight ==> *DY对象高度 document.do ...
- 转:JS获取浏览器高度和宽度
发现一篇好文章,汇总到自己的网站上. IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> ...
- js 获取浏览器高度和宽度值(多浏览器)
IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...
- 不同浏览器JS获取浏览器高度和宽度
摘自:http://blog.csdn.net/lai_gb/archive/2009/07/04/4320956.aspx IE中: document.body.clientWidth ==> ...
- js获取浏览器高度和宽度值,尽量的考虑了多浏览器。
js获取浏览器高度和宽度值,尽量的考虑了多浏览器. IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ...
- 关于JS中获取浏览器高度和宽度值的多种方法(多浏览器)
三种浏览器获取值方法 IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 ...
随机推荐
- zoj 1884 简单 键盘 字符 处理
WERTYU Time Limit: 2 Seconds Memory Limit: 65536 KB A common typing error is to place the hands ...
- c# 【MVC】WebApi开发实例
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using S ...
- PHP-FPM进程池探秘
PHP 支持多进程而不支持多线程:PHP-FPM 在进程池中运行多个子进程并发处理所有连接请求.通过 ps 查看PHP-FPM进程池(pm.start_servers = 2)状态如下: root@d ...
- 史上最难的一道Java面试题 (分析篇)
博客园 匠心零度 转载请注明原创出处,谢谢! 无意中了解到如下题目,觉得蛮好. 题目如下: public class TestSync2 implements Runnable { int b = 1 ...
- ReactiveCocoa_v2.5 源码解析之架构总览
ReactiveCocoa 是一个 iOS 中的函数式响应式编程框架,它受 Functional Reactive Programming 的启发,是 Justin Spahr-Summers 和 J ...
- win10 UWP 单元测试
我们在写代码的时候不能保证我们写出来的代码是正确的,所以我们经常要单元测试. 单元测试和重构都是在做完一个小小函数一般就要进行一次,越早做就越好,可以比较早发现问题,这时我们还记得我们写的内容,不过比 ...
- win10 uwp 视差效果
本文翻译:http://jamescroft.co.uk/blog/uwp/playing-with-scrolling-parallax-effects-on-ui-elements-in-wind ...
- 如何让vim像IDE一样一键放大缩小字号?
原创,转载请注明出处 在其他IDE中,比如codeblocks,按住ctrl,然后滑动鼠标滚轮就可以实现字体的放大缩小. 在强大的vim中code怎么能缺少这种功能?! 在vim插件库中查询一番,发现 ...
- C语言指针的那些坑
那些年把我们坑惨的指针 一.引言 当我们使用c语言的时候,不可避免的就得用到指针,然后对于刚刚接触C语言的猿兄们,可能会有点不适应,特别是刚刚从python等离硬件很远的语言转过来的. 下面我为大家总 ...
- Java基础总结--常用类以及包的访问权限
-----Object---所有类的根类1.怎么得到的:通过对所有对象不断的向上抽取共性,具备所有对象的共性的东西2.常用的方法* equals(Object obj):比较两个对象的引用是否指向同一 ...