2016-11-16 12 views
1

用紙の中心座標を見つける方法はありますか?c#等幅の印刷

多くのディスカッション、フォーラム、ヒントを読んでいましたが、できません。このような イム印刷:私はMarginBounds、Hardmarginsの使用を含む多くの方法でこれらの座標を計算してみました。もちろん、

 using (PrintDialog pd = new PrintDialog()) 
    { 
     if (pd.ShowDialog() != DialogResult.OK) return; 
     PrintDocument document = new PrintDocument(); 
     document.PrinterSettings = pd.PrinterSettings; 
     document.PrintPage += new PrintPageEventHandler(Document_PrintPage); 
     document.Print(); 
    } 

    private void Document_PrintPage(object sender, PrintPageEventArgs e) 
    { 
     int X = (int)e.PageSettings.PrintableArea.X; 
     int Y = (int)e.PageSettings.PrintableArea.Y; 
     int width = (int)e.PageSettings.PrintableArea.Width - X; 
     int height = (int)e.PageSettings.PrintableArea.Height - Y; 

     int centerX = (width - X)/2 + X; 
     int centerY = (height - Y)/2 + Y; 

     e.Graphics.DrawRectangle(Pens.Gray, new Rectangle(X, Y, width, height)); 
     e.Graphics.DrawLine(Pens.Black, centerX - 100, centerY, centerX + 100, centerY); 
     e.Graphics.DrawLine(Pens.Black, centerX, centerY - 100, centerX, centerY + 100); 
    } 

は、余白など

誰もが正確に紙の中央に何かを印刷する方法を知っています?

答えて

0

e.PageBoundsあなたが探しているのはPrintPageEventArgsです。これは、ページの総面積を表す長方形の領域を提供します。

int centerX = e.PageBounds.Width/2; 
int centerY = e.PageBounds.Height/2;