![](/img/trans.png)
[英]Fix browser dependencies with webBrowser component in Visual Studio C++ 2008 Windows Forms Application?
[英]Printing not working in Visual Studio 2008 Windows Forms Application
我嘗試使用PrintDocument組件在Visual Studio C ++ 2008中打印一個紅色矩形,這是我使用的代碼:
private:
void printDocument1_PrintPage(System::Object ^ sender,
System::Drawing::Printing::PrintPageEventArgs ^ e)
{
e->Graphics->FillRectangle(Brushes::Red,
Rectangle(500, 500, 500, 500));
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
printDocument1->PrintPage += gcnew
System::Drawing::Printing::PrintPageEventHandler
(this, &Form1::printDocument1_PrintPage);
}
我有打印機,如果您想知道的話,它可以工作。 上面的代碼在按下按鈕時應打印一個紅色矩形,但是它不起作用。 我究竟做錯了什么?
Click事件處理程序是錯誤的,每次單擊都會向PrintPage添加另一個事件處理程序。 該分配屬於表單構造函數。 這沒有用,因為您忘記了重要的電話,實際上並沒有要求它打印。 固定:
System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
printDocument1->Print();
}
使用PrintPreviewDialog保存樹。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.