I can not get the margins?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I can not get the margins what I set in control panel s print server property. After I set the paper as custom using printdialog,the margin is always 1 inch, who can tell me why it is?,thank you very much.the following is the code:
/// <summary><br/>
/// 设置数据窗口对应打印属性<br/>
/// </summary><br/>
/// <returns></returns><br/>
private bool SetPriner()<br/>
{<br/>
if (string.IsNullOrEmpty(ReportName))<br/>
{<br/>
MSBox.ShowInfo("没有设置报表名,请检查!");<br/>
return false;<br/>
}
System.Drawing.Printing.PrintDocument pDocument = new System.Drawing.Printing.PrintDocument();<br/>
PrintDialog printDialog = new PrintDialog();<br/>
printDialog.Document = pDocument;<br/>
if (dtPrinterSettting.Rows.Count > 0)<br/>
{<br/>
//恢复报表打印参数<br/>
RestorePrinter(pDocument);<br/>
}<br/>
DialogResult dialogResult = printDialog.ShowDialog();<br/>
if (dialogResult == DialogResult.OK)<br/>
{<br/>
//保存数据窗口打印机设置<br/>
pDocument = SavePrinter(pDocument, printDialog);<br/>
}<br/>
return true;<br/>
}
/// <summary><br/>
/// 保存数据窗口打印机设置<br/>
/// </summary><br/>
/// <param name="pDocument </param><br/>
/// <param name="printDialog </param><br/>
/// <returns></returns><br/>
private System.Drawing.Printing.PrintDocument SavePrinter(System.Drawing.Printing.PrintDocument pDocument, PrintDialog printDialog)<br/>
{<br/>
pDocument = printDialog.Document;<br/>
if (dtPrinterSettting.Rows.Count == 0)<br/>
{<br/>
DataRow dr = dtPrinterSettting.NewRow();<br/>
dr["PK_ID"] = Utility.StringService.PublicStrUtil.getGuid();<br/>
dr["REPORTNAME"] = ReportName;<br/>
dr["USERCODE"] = m_userName;<br/>
dr["SYSID"] = m_machineName;<br/>
dr["REPORTTYPE"] = "固定格式";<br/>
dtPrinterSettting.Rows.Add(dr);<br/>
}<br/>
//1/100英寸的整数值,使用时根据单位要做转换<br/>
dtPrinterSettting.Rows[0]["PRINTNAME"] = pDocument.PrinterSettings.PrinterName;<br/>
dtPrinterSettting.Rows[0]["MARGINTOP"] = pDocument.DefaultPageSettings.Margins.Top; here is alway 1 inch <br/>
dtPrinterSettting.Rows[0]["MARGINBOTT"] = pDocument.DefaultPageSettings.Margins.Bottom;
here is alway 1 inch <br/>
dtPrinterSettting.Rows[0]["MARGINRIGH"] = pDocument.DefaultPageSettings.Margins.Right;
here is alway 1 inch <br/>
dtPrinterSettting.Rows[0]["MARGINLEFT"] = pDocument.DefaultPageSettings.Margins.Left;
here is alway 1 inch <br/>
PaperSize pSize = pDocument.DefaultPageSettings.PaperSize;<br/>
dtPrinterSettting.Rows[0]["PAPERNAME"] = pSize.PaperName;<br/>
dtPrinterSettting.Rows[0]["CUSTOMSIGN"] = "0";<br/>
if (pSize.Kind == PaperKind.Custom) //自定义纸张<br/>
{<br/>
//自定义纸张,1/100英寸的整数值,使用时根据单位要做转换<br/>
dtPrinterSettting.Rows[0]["CUSTOMSIGN"] = "1";<br/>
dtPrinterSettting.Rows[0]["PAGEHEIGHT"] = pSize.Height; //1/100英寸的整数值<br/>
dtPrinterSettting.Rows[0]["PAGEWIDTH"] = pSize.Width; //1/100英寸的整数值<br/>
dtPrinterSettting.Rows[0]["PAGESIZE"] = 255;
}<br/>
else //非自定义纸张<br/>
{<br/>
if (m_paperSize.Contains(pSize.Kind.ToString()))<br/>
{<br/>
dtPrinterSettting.Rows[0]["PAGESIZE"] = m_paperSize[pSize.Kind.ToString()];<br/>
}<br/>
else<br/>
{<br/>
dtPrinterSettting.Rows[0]["PAGESIZE"] = m_paperSize["A4"];<br/>
}<br/>
dtPrinterSettting.Rows[0]["PAGEHEIGHT"] = 0;<br/>
dtPrinterSettting.Rows[0]["PAGEWIDTH"] = 0;<br/>
}<br/>
//打印方向,â1â代表横向,â2â代表纵向,â0â代表打印机默认值<br/>
dtPrinterSettting.Rows[0]["PAGEDIR"] = "0";<br/>
dtPrinterSettting.Rows[0]["PAGEDIR"] = (pDocument.DefaultPageSettings.Landscape) ? "1" : "2";<br/>
DataSet ds = new DataSet();<br/>
ds.Tables.Add(dtPrinterSettting.Copy());<br/>
ds.Tables[0].TableName = "SYSBILLFMT";<br/>
BLLBase.SaveData(ds);<br/>
return pDocument;<br/>
}

View the full article
 
Back
Top