1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#pragma once
namespace WinFormDemo {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Drawing::Printing::PrintDocument^ printDocument1;
protected:
private: System::Windows::Forms::PrintPreviewDialog^ printPreviewDialog1;
private: System::Windows::Forms::Button^ button1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager (Form1::typeid));
this->printDocument1 = (gcnew System::Drawing::Printing::PrintDocument ());
this->printPreviewDialog1 = (gcnew System::Windows::Forms::PrintPreviewDialog ());
this->button1 = (gcnew System::Windows::Forms::Button ());
this->SuspendLayout ();
//
// printDocument1
//
this->printDocument1->PrintPage += gcnew System::Drawing::Printing::PrintPageEventHandler (this, &Form1::printDocument1_PrintPage);
//
// printPreviewDialog1
//
this->printPreviewDialog1->AutoScrollMargin = System::Drawing::Size (0, 0);
this->printPreviewDialog1->AutoScrollMinSize = System::Drawing::Size (0, 0);
this->printPreviewDialog1->ClientSize = System::Drawing::Size (400, 300);
this->printPreviewDialog1->Enabled = true;
this->printPreviewDialog1->Name = L"printPreviewDialog1";
this->printPreviewDialog1->Visible = false;
//
// button1
//
this->button1->AutoSize = true;
this->button1->Location = System::Drawing::Point (75, 45);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size (253, 56);
this->button1->TabIndex = 0;
this->button1->Text = L"PrintPreview";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler (this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::None;
this->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->ClientSize = System::Drawing::Size (622, 435);
this->Controls->Add (this->button1);
this->Font = (gcnew System::Drawing::Font (L"Microsoft Sans Serif", 24, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Form1";
this->ResumeLayout (false);
this->PerformLayout ();
}
#pragma endregion
private: System::Void button1_Click (System::Object^ sender, System::EventArgs^ e)
{
printPreviewDialog1->Document = printDocument1;
printPreviewDialog1->ShowDialog ();
}
private: System::Void printDocument1_PrintPage (System::Object^ sender, System::Drawing::Printing::PrintPageEventArgs^ e)
{
e->Graphics->DrawString (L"Hello World", this->Font, Brushes::Red, 50, 50);
}
};
}
|