如何更改打印中的字体大小?

时间:2015-09-21 20:08:06

标签: c# winforms printing

如何更改打印的字体大小?这是我正在使用的代码。

private void PrintDocumentOnPrintPage(object sender, PrintPageEventArgs e)
{
     e.Graphics.DrawString(
        this.textBox5.Text + " " + this.textBox6.Text + " - " + this.textBox8.Text, 
        this.textBox5.Font, Brushes.Black, 10, 25);            
}

private void button1_Click(object sender, EventArgs e)
{
     MessageBox.Show("Bienvenido, Toma tú Gafete!");    
     PrintDocument printDocument = new PrintDocument();
     printDocument.PrintPage += PrintDocumentOnPrintPage;
     printDocument.Print();
}    

2 个答案:

答案 0 :(得分:0)

你可以使a new Font object与旧字体具有相同的族和风格,但大小不同;然后将该字体传递给DrawString而不是旧字体。

float size = 14; // for example
var oldFont = textBox5.Font;
var newFont = new Font(oldFont.FontFamily, size, oldFont.FontStyle);

e.Graphics.DrawString(
    this.textBox5.Text + " " + this.textBox6.Text + " - " + this.textBox8.Text, 
    newFont, Brushes.Black, 10, 25);            

答案 1 :(得分:0)

像这样创建一个新字体:

Font myFont = new Font(FontName, FontSize);

在此处查看文档:{​​{3}}