获取字符串宽度,特定字体,asp.net 网站和windows application都可以用

by 亿答案 20. 十一月 2009 10:21

首先,如果是asp.net 网站,先添加对System.Windows.Forms 的引用。在asp.net中添加对他的引用似乎不伦不类,管他呢,反正能解决问题

这是代码:

//定义一个control,需要用到它的一个方法CreateGraphics()来生成一个Graphics对象

//然后调用Graphics对象的MeasureString方法,传入字体名称,大小,样式(比如bold)等,去他的width属性即可得到传入字符串的宽度

System.Windows.Forms.Control c = new System.Windows.Forms.Control();

float width = c.CreateGraphics().MeasureString("这是需要获得宽度的字符串this is my string", new System.Drawing.Font("Georgia", 36, System.Drawing.FontStyle.Bold)).Width;


Tags: ,

.NET 编程

评论

2010/3/21 18:45:11 #

Canadian Government Grants

I am grateful to you for sharing this information.I have bookmarked your site for future updates.

Canadian Government Grants United Kingdom

2010/4/8 19:12:11 #

Business Planing

I am thankful to you for sharing such an informative post.

Business Planing United Kingdom

2010/4/22 20:17:25 #

jewellery earrings

good

jewellery earrings

2010/4/30 19:50:02 #

cheap brand shoes

This is something of a eulogy. I thought contacting its creator was the best way to let their lives end gracefully – in a full circle. They were unbelievable wholesale brand shoes, durable as all get-out and as stylish as Elvis on fire. It's time to let them go and move on to a new pair of cheap brand shoes. Like burying a family dog, setting them down is a hard task to do. But, alas, all things must end. http://www.freewholesale.net  

cheap brand shoes People's Republic of China

2010/5/19 21:16:01 #

Fatboy

Another fantastic post, usually awesome to go through an excellent post on the topic you truly care about.

Fatboy Denmark

2010/5/27 4:51:57 #

coach handbags

http://www.coachoutletfactory.com   coach outlet
http://www.coachoutletmalls.com    coach factory outlet
http://www.coach-handbags-outlet.com   coach handbags
            by zocy002 on 2010-7-22

coach handbags People's Republic of China

添加评论


(将显示你的Gravatar图标)

  Country flag

biuquote
  • 评论
  • 在线预览
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

RecentComments

Comment RSS