小编mik*_*iky的帖子

使用自定义字体在标签中绘制文本时,该参数无效

我有带有自定义字体和计时器的标签,它们会更改标签中的值。我的应用程序启动最小化。当我显示应用程序时,有时会显示异常,并且标签中的文本插入了红叉。

在这里我尝试调用异步方法来更改标签文本

private void timer1_Tick(object sender, EventArgs e)
    {
        // create a delegate of MethodInvoker poiting to showTime function.
        MethodInvoker simpleDelegate = new MethodInvoker(showTime);
        // Calling showTime Async
        simpleDelegate.BeginInvoke(null, null);
    }
Run Code Online (Sandbox Code Playgroud)

字体加载

public Form1()
    {
        InitializeComponent();

        SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch); //event handler for windows lock

        File.WriteAllBytes(appPath + "\\font.ttf", Resources.font); //copy font from resources

        try
        {
            PrivateFontCollection pfc = new PrivateFontCollection();
            pfc.AddFontFile(appPath + @"/font.ttf");
            label1.Font = new Font(pfc.Families[0], 11, FontStyle.Bold);
        }
        catch
        {
            MessageBox.Show("Failed to load nice font." + "\r\n" + …
Run Code Online (Sandbox Code Playgroud)

c# winforms custom-font

2
推荐指数
1
解决办法
1555
查看次数

标签 统计

c# ×1

custom-font ×1

winforms ×1