For this answer I use a helper function:
private static double ComputeSizeOfString(string text, string fontFamily, double fontSize)
{
System.Drawing.Font font = new(fontFamily, (float)fontSize);
System.Drawing.Image fakeImage = new System.Drawing.Bitmap(1, 1);
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(fakeImage);
return graphics.MeasureString(text, font).Width;
}
So basically the method uses a fakeimage with dimensions (1,1) to compute the length of the string, in this case the width of the image created from your chosen text.
An example of how to use it ends up like this:
string myTxt = "Hi there";
double szs = ComputeSizeOfString(myTxt, "Georgia", 14);
points = (pixels * (72.0 / 96.0))
– Clodhopping