PageSetupDialog中用的单位是百分之一英寸,而对话框上用的是毫米做单位;
PageSetupDialog默认页边距大小为100(百分之一英寸),而是对话框中默认大小为10毫米=3.9(百分之一英寸),所以你一调用对话框页边距就被改为3.9;要解决这个问题,只要在每次调用对话框之前把上、下、左、右页边距统统乘上2.533就可以了!this.storedPageSettings.Margins.Left*=2.533;
this.storedPageSettings.Margins.Right*=2.533;this.storedPageSettings.Margins.Top*=2.533;
this.storedPageSettings.Margins.Bottom*=2.533;pageSetupDialog.PageSettings = this.storedPageSettings;
pageSetupDialog.ShowDialog();一切OK!!
PageSetupDialog默认页边距大小为100(百分之一英寸),而是对话框中默认大小为10毫米=3.9(百分之一英寸),所以你一调用对话框页边距就被改为3.9;要解决这个问题,只要在每次调用对话框之前把上、下、左、右页边距统统乘上2.533就可以了!this.storedPageSettings.Margins.Left*=2.533;
this.storedPageSettings.Margins.Right*=2.533;this.storedPageSettings.Margins.Top*=2.533;
this.storedPageSettings.Margins.Bottom*=2.533;pageSetupDialog.PageSettings = this.storedPageSettings;
pageSetupDialog.ShowDialog();一切OK!!
private void button1_Click(object sender, System.EventArgs e)
{
try
{
if (this.storedPageSettings == null)
this.storedPageSettings = new PageSettings();
pageSetupDialog = new PageSetupDialog();
pageSetupDialog.PageSettings = this.storedPageSettings;
if (pageSetupDialog.ShowDialog() == DialogResult.OK)
{
pageSetupDialog.PageSettings.Margins =
PrinterUnitConvert.Convert(pageSetupDialog.PageSettings.Margins,PrinterUnit.ThousandthsOfAnInch, PrinterUnit.HundredthsOfAMillimeter); }
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
// 以下语句用于测试
#if DEBUG
MessageBox.Show(this.storedPageSettings.Margins.Left.ToString() + "\n" +
this.storedPageSettings.Margins.Right.ToString() + "\n" +
this.storedPageSettings.Margins.Top.ToString() + "\n" +
this.storedPageSettings.Margins.Bottom.ToString());
#endif }