방금 요청한 부품 용 데이터베이스 응용 프로그램을 만들었습니다.내 닷 닷넷 Windows 양식을 쉽게 인쇄 할 수 있습니까?
요청자 용, 수퍼바이저 승인 용, 구매 승인 용 및 사무원이 주문할 항목을 알기위한 여러 가지 양식이 있습니다.
저는 이제 종이없는 팬이되었지만 제 고용주는 자신의 논문을 정말로 좋아합니다. 내 Windows 양식을 종이로 복사하는 WYSIWYG 방법이 있습니까?
나는 또한 내가
감사
방금 요청한 부품 용 데이터베이스 응용 프로그램을 만들었습니다.내 닷 닷넷 Windows 양식을 쉽게 인쇄 할 수 있습니까?
요청자 용, 수퍼바이저 승인 용, 구매 승인 용 및 사무원이 주문할 항목을 알기위한 여러 가지 양식이 있습니다.
저는 이제 종이없는 팬이되었지만 제 고용주는 자신의 논문을 정말로 좋아합니다. 내 Windows 양식을 종이로 복사하는 WYSIWYG 방법이 있습니까?
나는 또한 내가
감사
에게 2.0 닷넷 프레임 워크를 사용하여 제한하고 있음을 추가해야합니다 다음은 원하는 것을 할 것입니다 code sample from MSDN입니다 : 몇 가지주의가
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printButton_Click(System.Object sender, System.EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
있습니다 - 여기에 예외 검사는 없으며, 관리되지 않는 BitBlt API를 사용하려면 완전히 신뢰해야합니다. 그러나 이것은 화면에 표시되는 한 Windows Forms 양식을 인쇄하는 가장 쉬운 방법 일 것입니다.
빠른 방법이 있습니다. 당신은 당신의 요구에 맞게 만들기 위해 코드를 정리할 수 있습니다 :이 페이지의 크기로 양식을 늘릴 것
public static class FormExtensions
{
public static void PrintForm(this Form f)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += (o, e) =>
{
Bitmap image = new Bitmap(f.ClientRectangle.Width, f.ClientRectangle.Height);
f.DrawToBitmap(image, f.ClientRectangle);
e.Graphics.DrawImage(image, e.PageBounds);
};
doc.Print();
}
}
. 원한다면 rhe DrawImage 메서드 호출의 두 번째 매개 변수를 조정하여 다른 곳에서 그릴 수 있습니다.