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

根据宽度来决定显示的字符串长度(C#)

根据宽度来决定显示的字符串长度 (C#,VS2005)
如果 lable长度固定但字符串长度可变,如果超过了lable显示的长度时,希望用 ...代替剩下的字符,这时需要一个函数
Graphics.MeasureString
具体代码如下
  public string Abbreviation(string str)
        {
            if (str == null)
            {
                return null;
            }
            int strWidth = FontWidth(txtName.Font, txtName, str);
            //获取label最长可以显示多少字符
            int len = label.Width * str.Length / strWidth;
            if (len > 3 && len < str.Length)
            {
                return str.Substring(0, len - 3) + "...";
            }
            else
            {
                return str;
            }
        }
        /// <summary>
        /// 获取字符串在 font时的长度
        /// </summary>
        private int FontWidth(Font font, Control control, s


相关文档:

asp.net c#数据库还原

public partial class shujuku_huanyuan : System.Web.UI.Page
{
    SqlConnection conn =  new SqlConnection(@"server=HUAZD-33\XXD33;uid=sa;pwd=111111;database=master;");
   
    protected void Page_Load(object sender, EventArgs e)
  &nbs ......

C# access日期查询加#

C# access日期查询加#
if (((string)((ComboBoxItem)cmbField.SelectedItem).Value).Equals("System.DateTime"))
{
                    //判断日期的;
        & ......

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 ......

根据字体大小得到字符串显示时的宽度(C#)

字符串的宽度自适应容器
 Graphics g = Graphics.fromImage(new Bitmap(1, 1));
 SizeF size = g.MeasureString(lblTitle.Text, new Font("宋体", 24 * 0.0625F, FontStyle.Bold));
 float oldSize=(800*0.0625F);//1px=0.0625em
 float newSize = (0.75F/size.Width )* oldSize;
size.Width 的单 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号