2012-06-10 63 views
0

我有一個窗體窗體。我想打印窗體內容而不顯示窗口。我的意思是我想打印它像收據一樣,沒有窗口邊框。我該怎麼做呢?c#如何打印沒有窗口窗體邊框的窗體形式

+3

Set FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; – adatapost

+0

爲什麼不在MSDN文檔上搜索? - > http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formborderstyle –

回答

-1

你可以得到一個空白的屏幕做這樣的事情

this.FormBorderStyle = System.Windows.Forms.FormsBorderStyle.None; 
this.ControlBox = false; 
this.Text = String.Empty; 
1

您可以就如何Print to a Windows Form MSDN的例子,改變表面的形式向面板控制,這將使正在印刷你打印無國界。您的內容將被添加到面板而不是表單,但它會起作用。這是MSDN示例的一個修改示例。

public class Form1 : Form 
{ 
    private Panel printPanel = new Panel(); 
    private Button printButton = new Button(); 
    private PrintDocument printDocument1 = new PrintDocument(); 

    public Form1() 
    { 
     printPanel.Size = this.ClientSize; 
     this.Controls.Add(printPanel); 
     printButton.Text = "Print Form"; 
     printButton.Click += new EventHandler(printButton_Click); 
     printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); 
     printPanel.Controls.Add(printButton); 

    } 

    void printButton_Click(object sender, EventArgs e) 
    { 
     CaptureScreen(); 
     printDocument1.Print(); 
    } 


    Bitmap memoryImage; 

    private void CaptureScreen() 
    { 
     Graphics myGraphics = printPanel.CreateGraphics(); 
     Size s = printPanel.Size; 
     memoryImage = new Bitmap(s.Width, s.Height, myGraphics); 
     Graphics memoryGraphics = Graphics.FromImage(memoryImage); 
     Point screenLoc = PointToScreen(printPanel.Location); // Get the location of the Panel in Screen Coordinates 
     memoryGraphics.CopyFromScreen(screenLoc.X, screenLoc.Y, 0, 0, s); 
    } 

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



    public static void Main() 
    { 
     Application.Run(new Form1()); 
    } 
}