2016-10-30 2 views
0

Windows Form을 인쇄하려고합니다.C# Windows 양식 인쇄 - 화면의 잘못된 영역을 인쇄합니다.

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
    { 
     e.Graphics.DrawImage(bmp, 0, 0); 
    } 

    Bitmap bmp; 

    private void button1_Click(object sender, EventArgs e) 
    { 
     Graphics g = this.CreateGraphics(); 
     bmp = new Bitmap(this.Size.Width, this.Size.Height, g); 
     Graphics mg = Graphics.FromImage(bmp); 
     mg.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size); 
     printDialog1.ShowDialog(); 
     printDocument1.Print(); 
     printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); 
    } 
} 

그러나 그것은 나에게이 결과 제공 : 내 솔루션입니다

Windows Form print issue

가 어떻게이 문제를 해결할 수 (프레임이 인쇄 된 용지의 경계를 보여주기 위해 만든 날입니다)을? 답에 대한 http://www.aspsnippets.com/Articles/Print-contents-of-Form-in-Windows-Forms-WinForms-Application-using-C-and-VBNet.aspx

답변

0

private void button1_Click(object sender, EventArgs e) 
{ 
    //Add a Panel control. 
    Panel panel = new Panel(); 
    this.Controls.Add(panel); 

    //Create a Bitmap of size same as that of the Form. 
    Graphics grp = panel.CreateGraphics(); 
    Size formSize = this.ClientSize; 
    bitmap = new Bitmap(formSize.Width, formSize.Height, grp); 
    grp = Graphics.FromImage(bitmap); 

    //Copy screen area that that the Panel covers. 
    Point panelLocation = PointToScreen(panel.Location); 
    grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize); 

    //Show the Print Preview Dialog. 
    printPreviewDialog1.Document = printDocument1; 
    printPreviewDialog1.PrintPreviewControl.Zoom = 1; 
    printPreviewDialog1.ShowDialog(); 
} 

참조를보십시오. 그것은 단지 형태로 확대하고 출력물은 나의 첫 번째 출력물과 거의 같지만 확대 된 차이점이 있습니다.

+0

감사합니다 :) 그러나 그것은 작동하지 않았다 : – qwerty

관련 문제