首页 > 解决方案 > 从 C# 打印并使文本自动居中

问题描述

我已经构建了一个从数据网格填充文本框的表单,我现在正试图在打印时让文本居中。我知道在这里我将所有内容都放在左侧,但是有没有办法让所有文本居中,同时我将图像保持在已定义的位置?文本的长度会因所选项目而异,但我需要将其居中,尽管长度。

private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
    e.Graphics.DrawImage(pictureBox.Image, 62, 73, 103, 120);

    e.Graphics.DrawString(cardLicenseTypeTextBox.Text, 
        new Font("Arial", 12, FontStyle.Regular), 
        Brushes.Black, 
        new RectangleF(0, 21, 197, 20));

    e.Graphics.DrawString(cardMemberNameTextBox.Text, 
        new Font("Arial", 12, FontStyle.Regular), 
        Brushes.Black, 
        new RectangleF(0, 242, 197, 20));

    e.Graphics.DrawString(cardAssociationTextBox.Text, 
        new Font("Arial", 12, FontStyle.Regular), 
        Brushes.Black, 
        new RectangleF(0, 260, 197, 20));

    e.Graphics.DrawImage(cardMemberNumberPictureBox.Image, 6, 281, 197, 21);

    e.Graphics.DrawString(cardMemberNumberTextBox.Text, 
        new Font("Arial", 12, FontStyle.Regular), 
        Brushes.Black, 
        new RectangleF(0, 309, 197, 20));
}

标签: c#printing

解决方案


推荐阅读