Изменение текста метки вызывает ошибку. Как решить ошибку пользовательского шрифта? - PullRequest
0 голосов
/ 17 июня 2020
• 1000 ?
    private void LoadFont()
    {
        PrivateFontCollection pfc = new PrivateFontCollection();
        int fontLength = Resources.Nexa_Regular.Length;
        byte[] fontdata = Resources.Nexa_Regular;
        System.IntPtr data = Marshal.AllocCoTaskMem(fontLength);
        Marshal.Copy(fontdata, 0, data, fontLength);
        pfc.AddMemoryFont(data, fontLength);
        lblStatus.Font = new Font(pfc.Families[0], lblStatus.Font.Size);
        Marshal.FreeCoTaskMem(data);
        pfc.Dispose();
    }
    private void MainForm_Load(object sender, EventArgs e)
    {
        LoadFont();
    }
    private void SetStatus()
    {
        if (IsActive())
        {
            lblStatus.Text = "Active"; // Error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt
            lblStatus.ForeColor = Color.Green;
        }
        else
        {
            lblStatus.Text = "Not Active";
            lblStatus.ForeColor = Color.Red;
        }
    }
...