C# Drawstring Letter Spacing

后端 未结 4 1891
说谎
说谎 2020-12-20 12:26

Is is somehow possible to control letter spacing when using Graphics.DrawString? I cannot find any overload to DrawString or Font that would allow me to do so.



        
4条回答
  •  温柔的废话
    2020-12-20 13:09

    Alternatively you could use the GDI API function SetTextCharacterExtra(HDC hdc, int nCharExtra) (MSDN documentation):

    [DllImport("gdi32.dll", CharSet=CharSet.Auto)] 
    public static extern int SetTextCharacterExtra( 
        IntPtr hdc,    // DC handle
        int nCharExtra // extra-space value 
    ); 
    
    public void Draw(Graphics g) 
    { 
        IntPtr hdc = g.GetHdc(); 
        SetTextCharacterExtra(hdc, 24); //set spacing between characters 
        g.ReleaseHdc(hdc); 
    
        e.Graphics.DrawString("str",this.Font,Brushes.Black,0,0); 
    }  
    

提交回复
热议问题