其中mRegistryRootKey 为软件的注册表位置
// 函数1 用于设置并将设置结果保存到注册表中 例子中只保存了上下左右,如果你有更多需要保存的自己扩展
PageSetupDialog psDlg = new PageSetupDialog();
PrinterSettings ps = new PrinterSettings();
psDlg.PageSettings = ps.DefaultPageSettings;
RegistryKey regPrint = Registry.LocalMachine.OpenSubKey(mRegistryRootKey + "PrintSetup\\", true);
if (regPrint != null)
{
Margins ms = new Margins();
ms.Left = Convert.ToInt32(regPrint.GetValue("Left", 100));
ms.Top = Convert.ToInt32(regPrint.GetValue("Top", 100));
ms.Right = Convert.ToInt32(regPrint.GetValue("Right", 100));
ms.Bottom = Convert.ToInt32(regPrint.GetValue("Bottom", 100));
if (System.Globalization.RegionInfo.CurrentRegion.IsMetric)
ms = PrinterUnitConvert.Convert(ms, PrinterUnit.Display, PrinterUnit.TenthsOfAMillimeter);
psDlg.PageSettings.Margins = ms;
}
else
{
regPrint = Registry.LocalMachine.CreateSubKey(mRegistryRootKey + "PrintSetup\\");
}
if (psDlg.ShowDialog() == DialogResult.OK)
{
regPrint.SetValue("Left", psDlg.PageSettings.Margins.Left, RegistryValueKind.String);
regPrint.SetValue("Top", psDlg.PageSettings.Margins.Top, RegistryValueKind.String);
regPrint.SetValue("Right", psDlg.PageSettings.Margins.Right, RegistryValueKind.String);
regPrint.SetValue("Bottom", psDlg.PageSettings.Margins.Bottom, RegistryValueKind.String);
}
psDlg.Dispose();
开始使用了 例子中是给XtraReport用
private void fnSetPrintCustom(XtraReport report)
{
RegistryKey regPrint = Registry.LocalMachine.OpenSubKeymRegistryRootKey +"PrintSetup\\", false);
if (regPrint != null)
{
int esLeft = Convert.ToInt32(regPrint.GetValue("Left", "-9999"));
int esTop = Convert.ToInt32(regPrint.GetValue("Top", "-9999"));
int esRight = Convert.ToInt32(regPrint.GetValue("Right", "-9999"));
int esBottom = Convert.ToInt32(regPrint.GetValue("Bottom", "-9999"));
if (esLeft != -99999) report.PrintingSystem.PageSettings.LeftMargin = esLeft;
if (esTop != -99999) report.PrintingSystem.PageSettings.TopMargin = esTop;
if (esRight != -99999) report.PrintingSystem.PageSettings.RightMargin = esRight;
if (esBottom != -99999) report.PrintingSystem.PageSettings.BottomMargin = esBottom;
}
}
其实很简单