易截截图软件、单文件、免安装、纯绿色、仅160KB

C#获取字符串的长度

C#获取字符串的长度
作者:ylclass  来源:博客园  发布时间:2009-10-30 16:25  阅读:193 次  原文链接   [收藏]  
1、    使用g.MeasureString()获得
使用MeasureString测量出来的字符宽度,总是比实际宽度大一些,而且随着字符的长度增大,貌似实际宽度和测量宽度的差距也越来越大了。查了一下MSDN,找到了下面这个理由:
MeasureString 方法旨在与个别字符串一起使用,它在字符串前后包括少量额外的空格供突出的标志符号使用。
            string str;
            str = "大";
            Font f = new Font("SimSun", 7F, System.Drawing.FontStyle.Regular);
            Graphics g = this.CreateGraphics();
            //单位为mm
            g.PageUnit = GraphicsUnit.Millimeter;
            SizeF sim = g.MeasureString(str, f);
2、使用TextRenderer.MeasureText获得,提供使用指定尺寸创建文本初始边框时,使用指定的设备上下文、字体和格式说明所绘制的指定文本的尺寸(以像素为单位)。
        private void MeasureText(PaintEventArgs e)
        {
            string str;
            str = "大家好";
            Font f = new Font("SimSun", 7F, System.Drawing.FontStyle.Regular);
            Size sif = TextRenderer.MeasureText(e.Graphics, str, f, new Size(0, 0), TextFormatFlags.NoPadding);
            M


相关文档:

Delphi 调用 C#的Webservice 不能传入参数


Delphi7 调用 C#的Webservice 不能传入参数
解决办法:
在Delphi导入WSDL后生成的单元的最后一行,即initialization里的初始化端口的代码中加入代码
InvRegistry.RegisterInvokeOptions(TypeInfo(接口名), ioDocument);
即可
 
 
......

asp.net c# 数据库备份

protected void btnsearch_ServerClick(object sender, EventArgs e)
    {
        string lujing=this.Text2.Value.ToString().Trim();
        string shujuku = this.jine.Value;
      &nbs ......

asp.netc#Access通用数据访问类

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
/// <summary>
/// Data ......

abstract(C# 参考)

//以下来自:http://msdn.microsoft.com/zh-cn/library/sf985hc5.aspx
abstract(C# 参考)
更新:2007 年 11 月
abstract 修饰符可以和类、方法、属性、索引器及事件一起使用。在类声明中使用 abstract 修饰符以指示某个类只能是其他类的基类。标记为抽象或包含在抽象类中的成员必须通过从抽象类派生的类来实现。
示例 ......

c# 将枚举作为键值的形式存储

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace 将枚举作为键值的形式存储
{
    enum Myenum
    {
       First=3,
       Second ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号