2012-12-31 2 views
7

가능한 중복 :
How can I take a screenshot of a Winforms control/form in C#?스크롤 가능한 창 양식 인쇄.

나는 창문이 이름과 사진의 목록을 형성합니다. 목록이 길어서 스크롤 패널이 있습니다. 자,이 양식을 인쇄하고 싶습니다만 인쇄 기능은 아래로 스크롤 할 때 보이지 않는 부분이 보이기 때문에 "보이는"부분 만 인쇄하기 때문에 인쇄 할 수 없습니다. 그래서, 한 번에 전체 양식을 인쇄하는 방법이 있습니까?

는 이 시도 스크롤 형식의 전체 클라이언트 영역을 인쇄하려면 Visual Basic의 파워팩 도구 상자

의 인쇄 폼 컨트롤에 대한

+3

그것은 정확한 속는 아니지만, 문제는 근본적으로 동일합니다. 여기에는 쉬운 해결책이 없습니다. 인쇄하려는 것은 실제로 존재하지 않습니다 (그리지 않았으므로). 인쇄하기 전에 양식을 스크롤하고 여러 이미지를 캡처해야합니다. 양식을 정확히 일치시키는 것에 대해 걱정하지 않고 데이터를 인쇄하는 것이 더 쉬울 수도 있습니다. –

+1

@ 존 B - 음, 이런 종류의 질문은이 반복적 인 문제에 대한 일반적인 대답을 찾는 데 도움이 될 수 있습니다. 가능한 복제본이 실제로 적용되지 않는 것 같습니다. 이렇게 "SO가 가능하지 않다"는 유일한 대답은 무엇입니까? –

답변

3

봐 ...

도구 상자 1.In,은 Visual Basic 파워팩을 클릭 탭을 클릭 한 다음 PrintForm 구성 요소를 폼으로 끌어옵니다.

PrintForm 구성 요소가 구성 요소 트레이에 추가됩니다.

2. 속성 창에서 PrintAction 속성을 PrintToPrinter로 설정합니다.

3. 적절한 이벤트 처리기 (예 : 인쇄 단추의 Click 이벤트 처리기)에 다음 코드를 추가하십시오.

1.PrintForm1.Print (나, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)

이 탄주고 내가 당신을 위해 밖으로 작동하는 방법을 알려 주시기 바랍니다.

+0

이것은 폼의 높이를 764 이상으로 확장 할 수 없다는 것을 확인하는 것은 정말 아프다. 나는 당신의 솔루션을 시도했다. 대형 양식에서는 작동하지 않습니다. 스크롤을 사용하여 폼에 대해이 작업을 수행하는 다른 방법이 있습니까? 감사 – Brune

2

이것은 완전한 대답은 아니지만 다음은 Form에서 스크롤 가능한 Panel 컨트롤의 스크린 샷 (비트 맵)을 사용하는 코드입니다. 큰 단점은 스크린 샷이 찍히는 동안 화면이 깜박입니다. 간단한 앱에서 테스트 했으므로 어떤 경우에도 작동하지 않을 수도 있지만 시작일 수 있습니다. 여기

은 그것을 사용하는 방법은 다음과 같습니다

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); // create a scrollable panel1 component 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     TakeScreenshot(panel1, "C:\\mypanel.bmp"); 
    } 
} 

을 그리고 여기에 유틸리티입니다 :

public static void TakeScreenshot(Panel panel, string filePath) 
    { 
     if (panel == null) 
      throw new ArgumentNullException("panel"); 

     if (filePath == null) 
      throw new ArgumentNullException("filePath"); 

     // get parent form (may not be a direct parent) 
     Form form = panel.FindForm(); 
     if (form == null) 
      throw new ArgumentException(null, "panel"); 

     // remember form position 
     int w = form.Width; 
     int h = form.Height; 
     int l = form.Left; 
     int t = form.Top; 

     // get panel virtual size 
     Rectangle display = panel.DisplayRectangle; 

     // get panel position relative to parent form 
     Point panelLocation = panel.PointToScreen(panel.Location); 
     Size panelPosition = new Size(panelLocation.X - form.Location.X, panelLocation.Y - form.Location.Y); 

     // resize form and move it outside the screen 
     int neededWidth = panelPosition.Width + display.Width; 
     int neededHeight = panelPosition.Height + display.Height; 
     form.SetBounds(0, -neededHeight, neededWidth, neededHeight, BoundsSpecified.All); 

     // resize panel (useless if panel has a dock) 
     int pw = panel.Width; 
     int ph = panel.Height; 
     panel.SetBounds(0, 0, display.Width, display.Height, BoundsSpecified.Size); 

     // render the panel on a bitmap 
     try 
     { 
      Bitmap bmp = new Bitmap(display.Width, display.Height); 
      panel.DrawToBitmap(bmp, display); 
      bmp.Save(filePath); 
     } 
     finally 
     { 
      // restore 
      panel.SetBounds(0, 0, pw, ph, BoundsSpecified.Size); 
      form.SetBounds(l, t, w, h, BoundsSpecified.All); 
     } 
    }