• VB调用自持字体


    VB调用自制字体
    我这里有一个C#的例子,请问如何在VB中实现啊。

    我们写exe程序时,默认字体是宋体,比较难看,指定了其他字体,但是其他用户上没有你指定的这个字体的话,也会变成默认的宋体。解决的办法有这么几个:
                1,叫用户安装相应字体,这个基本不可能实现,因为没有几个人会进行这样的操作;
      2,给用户安装相应字体,这个办法可行,在制作安装包时将字体打包进去,然后用户安装程序的时候连字体也一并安装上去,一劳永逸;
                3,把字体导入到程序资源中,让程序直接调用字体资源,缺点是导致程序体积巨大;
                4,将字体文件放到程序目录里,在程序里单独调用。
                个人觉得第4种办法比较方便,所以决定采用这种方法,把代码写出来给需要的同学。
                引用:
                using System.Drawing.Text;
                public void Setfont()
                        {
                         string AppPath = Application.StartupPath;
                            try
                            {
                                PrivateFontCollection font = new 
                PrivateFontCollection();
                                font.AddFontFile(AppPath + 
                @"fontmsyh.ttf");//字体的路径及名字 
                                Font myFont = new Font(font.Families[0].Name, 
                9F,FontStyle.Regular,GraphicsUnit.Point, ((byte)(134)));
                                //设置窗体控件字体,哪些控件要更改都写到下面
                                label1.Font = myFont;
                                label2.Font = myFont;
                                label3.Font = myFont;
                                button1.Font = myFont;
                                button2.Font = myFont;
                                button3.Font = myFont;
                                button4.Font = myFont;
                                button5.Font = myFont;
                            }
                            catch
                            { 
                                MessageBox.Show("字体不存在或加载失败 程序将以默认字体显示", "警告", 
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                 
                然后在public Form1()
                        { 
                            InitializeComponent();
                            Setfont();//启动字体设置函数
                       }

    感谢各位了。

    ------解决方案--------------------
    AddFontResource(App.path & "SheDllListA.TTF")
    Call SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)

    这两句加到窗体显示之前就行了

  • 相关阅读:
    java课后思考问题(二)
    论文-MS-CNN
    论文-ION--Inside-Outside Net: Detecting Objects in Context with Skip
    51Nod--1285-山峰和分段
    论文-Learning Features and Parts for Fine-Grained Recognition
    论文-Multi-view Convolutional Neural Networks for 3D Shape Recognition
    论文-SPP_net
    Leetcode 448. Find All Numbers Disappeared in an Array
    FlowNet
    LeetCode Weekly Contest 21
  • 原文地址:https://www.cnblogs.com/aibo/p/3442074.html
Copyright © 2020-2023  润新知