c# - 从 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));
}
解决方案
推荐阅读
- javascript - 修复 IE11 中的 let 变量声明?
- javascript - 使用 Id 删除脚本
- java - 将多个键匹配到模式中
- java - java属性文件中的属性键
- git - 我如何在新的远程分支上使用 git push?
- pyspark - Pyspark 基于其他列和运行计数器添加列
- java - OSGI Bundle:ConfigurationAdmin 在其中有“=”时截断键
- javascript - 从子文件夹导入文件的最有效方法?
- reactjs - Auth.federatedSignIn 在重定向时没有给我一个经过身份验证的用户
- asp.net - /Account/Login Post 方法返回 500