2011-04-21 4 views
28

PictureBox에 이미지가 있고이를 인쇄하려고합니다. 아무 서식도, 아무 것도, 다만 인쇄하지 말라.이미지 인쇄 C# .net

저는 Google에서 검색했지만 아무 것도 없으며 양식이나 텍스트 또는 보고서를 인쇄하는 사람 만 있습니다.

private string imgSrc; 

    public string ImgSrc 
    { 
     get { return imgSrc; } 
     set { imgSrc = value; } 
    } 

    public Id_Manager() 
    { 
     ImgSrc = "D:\\Foto.jpg"; 

     InitializeComponent(); 
     idPicture.Load(this.ImgSrc); 
    } 

분명히 이미지가 변경 될 예정이지만, 지금은 그 이미지를 인쇄하는 데 관심이 있습니다. 나는 경우에 대비해 속성에 URL을 저장합니다. 어떤 도움이 필요합니까?

답변

50

아래 코드는 printDocument 개체를 사용하여 이미지를 인쇄 문서에 배치 한 다음 인쇄 할 수 있습니다.

using System.Drawing.Printing; 
... 
protected void btnPrint_Click(object sender, EventArgs e) 
{ 
    PrintDocument pd = new PrintDocument(); 
    pd.PrintPage += PrintPage; 
    pd.Print();  
} 

private void PrintPage(object o, PrintPageEventArgs e) 
{ 
    System.Drawing.Image img = System.Drawing.Image.FromFile("D:\\Foto.jpg"); 
    Point loc = new Point(100, 100); 
    e.Graphics.DrawImage(img, loc);  
} 
+0

아주 많이는 마지막 줄에 –

+0

매우 helpfull했다 감사를, 그것은 "IMG"해야하지 " ing ":-) – itsho

+12

printPage ("... ")에"img "를 처리하는 것을 잊지 마세요. 그렇지 않으면 IOException을 사용하여 두 번째 인쇄에 매달리게됩니다. – itsho

8

위치를 사용하여, 나는 그것을 수행이에서는 FileInfo 확장 방법이 있습니다

public static void Print(this FileInfo value) 
{ 
    Process p = new Process(); 
    p.StartInfo.FileName = value.FullName; 
    p.StartInfo.Verb = "Print"; 
    p.Start(); 
}