gpt4 book ai didi

c++ - 打印在 Visual Studio 2008 Windows 窗体应用程序中不起作用

转载 作者:行者123 更新时间:2023-11-28 08:12:09 25 4
gpt4 key购买 nike

我尝试使用 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 保存一棵树。

关于c++ - 打印在 Visual Studio 2008 Windows 窗体应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8761258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com