当我尝试打印时,我想上传带有一些string
值的图像以进行打印,但是我无法指定图像的宽度和高度。我想像页面标题一样显示它,并给它恒定的宽度和高度。
以下是上传图片的代码:
private void button2_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
imageLocation = dialog.FileName;
pictureBox1.ImageLocation = imageLocation;
//pictureBox1.Image.Width(100);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
打印代码:
e.Graphics.DrawImage(System.Drawing.Image.FromFile(imageLocation), e.PageBounds);
e.Graphics.DrawString(labelProjectNum.Text,
new Font("Times New Roman", 12, FontStyle.Underline),
Brushes.Black,
new Point(700, 200));
e.Graphics.DrawString(projectNumber.Text,
new Font("Times New Roman", 12, FontStyle.Regular),
Brushes.Black,
new Point(650, 200));