P a u l
P a u l

Reputation: 7921

System.Drawing: how to control font weight?

I find I can't change the font weight even though I am creating it via win32 pinvoke. I'm using Graphics.DrawString to use the font. I'm stumped and can't find anything on this.

[DllImport("gdi32.dll")]
static extern IntPtr CreateFont(int nHeight, int nWidth, int nEscapement,
   int nOrientation, int fnWeight, uint fdwItalic, uint fdwUnderline, uint
   fdwStrikeOut, uint fdwCharSet, uint fdwOutputPrecision, uint
   fdwClipPrecision, uint fdwQuality, uint fdwPitchAndFamily, string lpszFace);

private void CreateLabelFont()
{
    // Remove -13 magic number later.
    IntPtr hFont = CreateFont(-13, 0, 0, 0, 100, 0, 0, 0, 1, 0, 0, 0, 0, "Arial\0");
    labelFont = Font.FromHfont(hFont);
}

Upvotes: 1

Views: 3234

Answers (1)

dirkgently
dirkgently

Reputation: 111316

From MSDN reference for CreateFont:

fnWeight [in] Specifies the weight of the font in the range 0 through 1000. For example, 400 is normal and 700 is bold. If this value is zero, a default weight is used.

This means you fix the weight when you create a font. In case you need different font-weights, you'll have to call CreateFont multiple times.

Upvotes: 1

Related Questions