如题,在vc2003的对话框中如何使用.NET Framework类库中的 PrintPreviewDialog类???

解决方案 »

  1.   

    2种方法,
    1是使用C++/CLI编译,添加PrintPreviewDialog的引用。
    2是使用宿主API的方式。
      

  2.   

    按照方法一,对话框是弹出来了,但是我要把下面的这些代码加进去,该怎么做   // Declare the dialog.
    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 );
       }
      

  3.   

    目前PrintPreviewDialog^ PrintPreviewDialog1;这个声明我是作为局部变量放在函数里声明的,按照方法一,对话框是弹出来了,但是我要把PrintPreviewDialog作为全局变量,该怎么做。
      

  4.   


    和普通全局变量一样,在放全局变量的地方gcnew一个就可以了。不一定要放在类里面。