如题,在vc2003的对话框中如何使用.NET Framework类库中的 PrintPreviewDialog类???
解决方案 »
- 高考志愿填报---寻求建议!
- 请问,我们自己应用程序exe文件放在C:\WINNT\system32\目录下,运行速度和效率是不是有所提高?
- VC++类型转换整理
- 不知道自己的路该怎么走,请大家给我指点一下吧?
- 在NT4.0下如何不自己写驱动而去写并口的控制寄存器(有IO地址)
- 怎么把自己的数据复制到剪切板中呀?
- 请教Singleton(单件)模式中 static 声明是如何保证一个类只有一个实例的?
- POPUP菜单尺寸
- 有那位dx知道什么软件可以将java源程序转换为c++的? 送50:)
- 问几个visual studio里面的简单问题
- 两个类之间的成员函数调用问题
- =====短信群发软件=====
1是使用C++/CLI编译,添加PrintPreviewDialog的引用。
2是使用宿主API的方式。
internal:
PrintPreviewDialog^ PrintPreviewDialog1;private: // Declare a PrintDocument object named document.
System::Drawing::Printing::PrintDocument^ document; // Initalize the dialog.
void InitializePrintPreviewDialog()
{
// Create a new PrintPreviewDialog using constructor.
this->PrintPreviewDialog1 = gcnew PrintPreviewDialog;
//Set the size, location, and name.
this->PrintPreviewDialog1->ClientSize = System::Drawing::Size( 400, 300 );
this->PrintPreviewDialog1->Location = System::Drawing::Point( 29, 29 );
this->PrintPreviewDialog1->Name = "PrintPreviewDialog1";
// Associate the event-handling method with the
// document's PrintPage event.
this->document->PrintPage += gcnew System::Drawing::Printing::PrintPageEventHandler( this, &Form1::document_PrintPage );
// Set the minimum size the dialog can be resized to.
this->PrintPreviewDialog1->MinimumSize = System::Drawing::Size( 375, 250 );
// Set the UseAntiAlias property to true, which will allow the
// operating system to smooth fonts.
this->PrintPreviewDialog1->UseAntiAlias = true;
} void Button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
if ( TreeView1->SelectedNode != nullptr )
{
document->DocumentName = TreeView1->SelectedNode->Tag->ToString();
} // Set the PrintPreviewDialog.Document property to
// the PrintDocument object selected by the user.
PrintPreviewDialog1->Document = document;
// Call the ShowDialog method. This will trigger the document's
// PrintPage event.
PrintPreviewDialog1->ShowDialog();
} void document_PrintPage( Object^ /*sender*/, System::Drawing::Printing::PrintPageEventArgs^ e )
{
// Insert code to render the page here.
// This code will be called when the PrintPreviewDialog.Show
// method is called.
// The following code will render a simple
// message on the document in the dialog.
String^ text = "In document_PrintPage method.";
System::Drawing::Font^ printFont = gcnew System::Drawing::Font( "Arial",35,System::Drawing::FontStyle::Regular );
e->Graphics->DrawString( text, printFont, System::Drawing::Brushes::Black, 0, 0 );
}
和普通全局变量一样,在放全局变量的地方gcnew一个就可以了。不一定要放在类里面。