【174】C#添加非默认字体

参考:C# WinForm程序安装字体或直接调用非注册字体

参考:百度知道

  在Debug文件夹下面新建一个font的文件夹,然后将字体的文件复制到里面,使用的时候,直接调用字体文件!

        private void Form1_Load(object sender, EventArgs e)
        {
            String ls_appPath = System.Windows.Forms.Application.StartupPath + "\\font\\";//font是程序

            String fontFile1 = ls_appPath + "ygyxsziti2.0.TTF";

            System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();

            pfc.AddFontFile(fontFile1);//字体文件的路径
            
            Font myFont1 = new Font(pfc.Families[0], 41, FontStyle.Regular, GraphicsUnit.Point, 0);//myFont1就是你创建的字体对象

            textBox1.Font = myFont1;
        }

实例二:

String ls_appPath = System.Windows.Forms.Application.StartupPath + "\\font\\";//font是程序

String fontFile1 = ls_appPath + "LCDM2N__.TTF";
String fontFile2 = ls_appPath + "张海山锐线体简1.0.TTF";

System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();

pfc.AddFontFile(fontFile1);//字体文件的路径
pfc.AddFontFile(fontFile2);//字体文件的路径

Font myFont1 = new Font(pfc.Families[0], lb_hour.Font.Size);//myFont1就是你创建的字体对象
Font myFont2 = new Font(pfc.Families[1], lb_nowDate.Font.Size);//myFont1就是你创建的字体对象

lb_hour.Font = lb_mh1.Font = lb_mh2.Font = lb_minite.Font = lb_second.Font = myFont1;
lb_nowDate.Font = lb_week.Font = myFont2;

转载于:https://www.cnblogs.com/alex-bn-lee/p/4940712.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
默认情况下,当你将 `RichTextBox` 中的文本复制到剪贴板时,只会复制纯文本,并不会复制文本的样式(例如字体、颜色、大小等)。如果你想要复制文本样式,你需要在代码中进行一些额外的操作。 你可以使用 `DataObject` 类来自定义剪贴板数据的格式。下面是一个例子,展示了如何将 `RichTextBox` 中选定的文本及其样式复制到剪贴板: ```c# private void CopyToClipboard() { // 获取选定的文本及其样式 string selectedText = richTextBox1.SelectedRtf; // 创建一个 DataObject 对象,并将选定的文本及其样式添加到其中 DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.Rtf, selectedText); // 将 DataObject 对象添加到剪贴板中 Clipboard.SetDataObject(dataObject, true); } ``` 上述代码中,`DataFormats.Rtf` 表示复制的数据格式为 RTF 格式,这个格式可以保存文本的样式信息。 当你想要将剪贴板中的 RTF 格式的文本粘贴到 `RichTextBox` 中时,可以使用 `DataObject` 类中的 `GetData` 方法获取剪贴板数据,并将其设置为 `RichTextBox` 的 `SelectedRtf` 属性的值。示例如下: ```c# private void PasteFromClipboard() { // 从剪贴板中获取 RTF 格式的文本 string rtfText = Clipboard.GetData(DataFormats.Rtf) as string; // 将 RTF 格式的文本设置为 RichTextBox 的 SelectedRtf 属性的值 if (!string.IsNullOrEmpty(rtfText)) { richTextBox1.SelectedRtf = rtfText; } } ``` 希望这可以帮助你解决问题!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值