明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 7093|回复: 5

[符号表] 如何修改默认字体呀

[复制链接]
发表于 2010-12-29 17:13 | 显示全部楼层 |阅读模式
我在vs2008 c#环境下写了如下程序:

            DBText mytext = new DBText();
            mytext.TextString = text;   // TextString Contents
            mytext.Position = Position; // location position
            mytext.VerticalMode = TextVerticalMode.TextVerticalMid; //垂直对齐方式
            mytext.HorizontalMode = TextHorizontalMode.TextFit; //水平对齐方式
            mytext.AlignmentPoint = Position; //文本的坐标

但是不知道如何加字体样式呀,因为默认的是:Standard 我想修改成“宋体”, 但不知道如何做,请高手指点,谢谢!
发表于 2010-12-29 17:47 | 显示全部楼层
 楼主| 发表于 2010-12-30 22:08 | 显示全部楼层
怎么能把: TextStyle 字体修改成:“宋体”呀?
发表于 2010-12-30 22:54 | 显示全部楼层
 楼主| 发表于 2010-12-30 23:00 | 显示全部楼层
已解决了,谢谢超级版本
DBText mytext = new DBText();
mytext.TextStyle = AddTextStyle("宋体", "1", "3", 20, 20);

//建立文字样式
        public static ObjectId AddTextStyle(string name, string smallfont, string bigfont, double height, double xscale)
        {
            Database dbH = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = dbH.TransactionManager.StartTransaction())
            {
                TextStyleTable TST = (TextStyleTable)trans.GetObject(dbH.TextStyleTableId, OpenMode.ForWrite);
                ObjectId id =  GetIdFromSymbolTable(TST, name);
                if (id == ObjectId.Null)
                {
                    TextStyleTableRecord TSTR = new TextStyleTableRecord();
                    TSTR.Name = name;
                    TSTR.FileName = smallfont;
                    TSTR.BigFontFileName = bigfont;
                    TSTR.TextSize = height;
                    TSTR.XScale = xscale;
                    TST.UpgradeOpen();
                    id = TST.Add(TSTR);
                    trans.AddNewlyCreatedDBObject(TSTR, true);
                }
                return id;
            }
        }

        //取得符号表的Id
        public static ObjectId GetIdFromSymbolTable(SymbolTable st, string key)
        {
            Database dbH = HostApplicationServices.WorkingDatabase;
            using (Transaction trans = dbH.TransactionManager .StartTransaction ())
            {
                if (st.Has(key))
                {
                    ObjectId idres = st[key];
                    if (!idres.IsErased)
                        return idres;
                    foreach (ObjectId id in st)
                    {
                        if (!id.IsErased)
                        {
                            SymbolTableRecord str = (SymbolTableRecord)trans.GetObject(id, OpenMode.ForRead);
                            if (str.Name == key)
                                return id;
                        }
                    }
                }
            }
            return ObjectId.Null;
        }
发表于 2015-2-21 16:16 | 显示全部楼层
受教了。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 07:30 , Processed in 0.209206 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表