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对象高度 ...
随机推荐
- svn服务端安装、权限修改以及客户端的使用
2017-10-1016:10:2 svn服务端安装.权限修改以及客户端的使用 svn服务端.客户端.汉化包下载 http://pan.baidu.com/s/1c1Ogj2C 1.安装服务器端程序( ...
- Python实战之列表简单练习
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__ ...
- Mysq基础
本文是之前看博客时候的记录,忘记是哪位仁兄的了,在这只做一次转载: 常见误区 count(1)和count(primary_key) 优于 count(*) 很多人为了统计记录条数,就使用 count ...
- gitlab服务器搭建教程
gitlab服务器搭建教程 ----2016年终总结 三 参考https://bbs.gitlab.cc/topic/35/gitlab-ce-8-7-%E6%BA%90%E7%A0%81%E5%AE ...
- 使用Canvas制作时钟动画
复习Javascript到Canvas的知识点,看到一个使用Canvas绘制的静态时钟例子,便想将其变成动态显示系统时间的时钟动画.另外再配上数字显示的时钟,一个小的时钟模块的诞生了!目前的界面还比较 ...
- jquery各种事件使用方法总结(from:天宇之游)
ps:本博客转自博主 天宇之游 ,地址:http://www.cnblogs.com/cwp-bg/ ,再次感谢天宇之游.jquery事件使用方法总结 一.鼠标事件1. click():鼠标单击事 ...
- win10 uwp 访问解决方案文件
本文讲如何访问解决方案的资源. 我们经常会把一些图片资源放在我们的解决方案,那么从这里拿出来很简单. 我在 Assets 放了图片 1.jpg 那么我要把他拿出来可以 <Image Source ...
- ubuntu 14.04 vim YoucompleteMe 代码自动补全工具安装
安装步骤如下: sudo apt-get install vim ; sudo apt-get install vim-youcompleteme ; sudo apt-get install vim ...
- 浅谈 var 关键字
提起 var关键子,程序员的第一反应就是JavaScript, 事实上这个关键子在其他语言中也有被采用. 比如说C#, 比如说kotlin, 用法和JavaScript中使用差不多,作为要声明变量的前 ...
- 锁对象Lock
Lock 实现提供了比使用synchronized 方法和语句可获得的更广泛的锁定操作,它能以更优雅的方式处理线程同步问题: public class LockTest { publicstaticv ...