I use this code to get the embedded font:
I use Thread to try to wait for it to complete, because an error occurs if this method is called several times in a short amount of time.
How can I stop this error, I think it has something to do with the method being called in quick succession of each other.
I get an exception here:
_font = value; using (Graphics g = _parent.CreateGraphics()) { SizeF soize = g.MeasureString(_text, _font); _size = new Size((int)soize.Width, (int)soize.Height); _width = _size.Width; _height = _size.Height; }
On line g.MeasureString (_text, _font);
However, I know that the error is in the GetEmbeddedFont method, since it only throws an error if the font is specified using the GetEmbeddedFont method.
It will work fine once, but if it is used a second time shortly after the first, it will throw an error.
And if I debug the code, _font returns this:
{Name = '((System.Drawing.Font)(_font)).fontFamily.Name' threw an exception of type 'System.ArgumentException' Size=15.0}
source share