Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Microsoft Visual C++ .NET Professional Projects - Premier Press

.pdf
Скачиваний:
180
Добавлен:
24.05.2014
Размер:
26 Мб
Скачать

410 Project 2 CREATING AN APPLICATION USING MANAGED C++

else

{

return;

 

}

 

 

 

 

 

 

 

//END FORM

 

 

 

 

 

 

FontDialog* pFontDialog;

 

 

 

Y

 

pFontDialog = new FontDialog();

 

 

 

 

 

 

 

 

 

 

 

 

L

 

 

 

 

 

F

 

Color colorTxtColor = Color::Black;

 

 

 

Drawing::Font* pTxtFont;

M

 

 

if ( pFontDialog->ShowDialog() != DialogResult::Cancel )

 

{

 

A

 

 

 

 

 

 

 

 

 

 

 

colorTxtColor = pFontDialog->get_Color();

 

 

 

E

 

 

 

 

 

pTxtFont = pFontDialog->get Font();

 

}

T

 

 

 

 

 

 

 

 

 

 

 

 

pActiveView->Handle extDraw(pstrText, pTxtFont, colorTxtColor);

}

 

 

 

 

 

 

 

void CMainWindow::DrawLine()

 

 

 

 

{

 

 

 

 

 

 

 

 

Form* f = new Form();

 

 

 

 

 

//Get the document of active view

 

 

 

CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*> (this-

>ActiveMdiChild);

 

 

 

 

 

 

CGDIPlusDoc* pActiveDoc = pActiveView->GetDocument();

 

f->AutoScaleBaseSize = System::Drawing::Size(5, 13);

 

f->Text = “Draw Line”;

 

 

 

 

 

f->ClientSize =

System::Drawing::Size(300, 125);

 

Button* button1 = new Button();

 

 

 

 

button1->Location = System::Drawing::Point(70, 100);

 

button1->Size =

System::Drawing::Size(60, 20);

button1->TabIndex = 1; button1->Text = “OK”;

Team-Fly®

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 411

button1->DialogResult = System::Windows::Forms::DialogResult::OK ;//Make this “OK” button

Button* button2 = new Button();

button2->Location = System::Drawing::Point(150, 100); button2->Size = System::Drawing::Size(60, 20); button2->TabIndex = 6;

button2->Text = “Cancel”;

//Left

TextBox* textBox1 = new TextBox();

textBox1->Location = System::Drawing::Point(80, 15); textBox1->Text = “10”; //pActiveDoc->nThinWidth.ToString(); textBox1->TabIndex = 1;

textBox1->Size = System::Drawing::Size(64, 20);

//Top

TextBox* textBox2 = new TextBox();

textBox2->Location = System::Drawing::Point(80, 45); textBox2->Text = “10”; //pActiveDoc->nThickWidth.ToString(); textBox2->TabIndex = 2;

textBox2->Size = System::Drawing::Size(64, 20);

Label* label1 = new Label();

label1->Location = System::Drawing::Point(15, 20); label1->Text = “Point1-X:”;

label1->Size = System::Drawing::Size(55, 16); label1->TabIndex = 3;

Label* label2 = new Label();

label2->Location = System::Drawing::Point(15, 50); label2->Text = “Point1-Y:”;

label2->Size = System::Drawing::Size(55, 16); label2->TabIndex = 4;

//PSK START

TextBox* textBox3 = new TextBox();

textBox3->Location = System::Drawing::Point(220, 15);

412 Project 2 CREATING AN APPLICATION USING MANAGED C++

textBox3->Text = “50”; //pActiveDoc->nThinWidth.ToString(); textBox3->TabIndex = 1;

textBox3->Size = System::Drawing::Size(64, 20);

TextBox* textBox4 = new TextBox();

textBox4->Location = System::Drawing::Point(220, 45); textBox4->Text = “25”; //pActiveDoc->nThickWidth.ToString(); textBox4->TabIndex = 2;

textBox4->Size = System::Drawing::Size(64, 20);

Label* label3 = new Label();

label3->Location = System::Drawing::Point(155, 20); label3->Text = “Point2-X:”;

label3->Size = System::Drawing::Size(55, 16); label3->TabIndex = 3;

Label* label4 = new Label();

label4->Location = System::Drawing::Point(155, 50); label4->Text = “Point2-Y:”;

label4->Size = System::Drawing::Size(55, 16); label4->TabIndex = 4;

//END

f->FormBorderStyle = FormBorderStyle::FixedDialog;

//Set the MaximizeBox to false to remove the maximize box. f->MaximizeBox = false;

//Set the MinimizeBox to false to remove the minimize box. f->MinimizeBox = false;

//Set the accept button of the form to button1.

f->AcceptButton = button1;

// Set the cancel button of the form to button2. f->CancelButton = button2;

f->StartPosition = FormStartPosition::CenterScreen;

f->Controls->Add(button1); f->Controls->Add(button2);

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 413

f->Controls->Add(label1); f->Controls->Add(label2); f->Controls->Add(label3); f->Controls->Add(label4); f->Controls->Add(textBox1); f->Controls->Add(textBox2); f->Controls->Add(textBox3); f->Controls->Add(textBox4);

System::Windows::Forms::DialogResult res = f->ShowDialog(); if(res == System::Windows::Forms::DialogResult::OK )

{

pActiveDoc->nShapeLeft = UInt16::Parse(textBox1->Text); pActiveDoc->nShapeTop = UInt16::Parse(textBox2->Text); pActiveDoc->nShapeWidth = UInt16::Parse(textBox3->Text); pActiveDoc->nShapeHeight = UInt16::Parse(textBox4->Text); pActiveView->HandleLineDraw();

f->Close();

}

}

void CMainWindow::DrawFilledEllipse()

{

Form* f = new Form();

//Get the document of active view

CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*> (this- >ActiveMdiChild);

CGDIPlusDoc* pActiveDoc = pActiveView->GetDocument();

f->AutoScaleBaseSize = System::Drawing::Size(5, 13);

f->Text = “Draw Filled Ellipse”;

f->ClientSize = System::Drawing::Size(300, 125);

Button* button1 = new Button();

button1->Location = System::Drawing::Point(70, 100); button1->Size = System::Drawing::Size(60, 20); button1->TabIndex = 1;

414 Project 2 CREATING AN APPLICATION USING MANAGED C++

button1->Text = “OK”;

button1->DialogResult = System::Windows::Forms::DialogResult::OK ; //Make this “OK” button

Button* button2 = new Button();

button2->Location = System::Drawing::Point(150, 100); button2->Size = System::Drawing::Size(60, 20); button2->TabIndex = 6;

button2->Text = “Cancel”;

//Left

TextBox* textBox1 = new TextBox();

textBox1->Location = System::Drawing::Point(80, 15); textBox1->Text = “10”; //pActiveDoc->nThinWidth.ToString(); textBox1->TabIndex = 1;

textBox1->Size = System::Drawing::Size(64, 20);

//Top

TextBox* textBox2 = new TextBox();

textBox2->Location = System::Drawing::Point(80, 45); textBox2->Text = “10”; //pActiveDoc->nThickWidth.ToString(); textBox2->TabIndex = 2;

textBox2->Size = System::Drawing::Size(64, 20);

Label* label1 = new Label();

label1->Location = System::Drawing::Point(15, 20); label1->Text = “Left:”;

label1->Size = System::Drawing::Size(50, 16); label1->TabIndex = 3;

Label* label2 = new Label();

label2->Location = System::Drawing::Point(15, 50); label2->Text = “Top:”;

label2->Size = System::Drawing::Size(50, 16); label2->TabIndex = 4;

//PSK START

TextBox* textBox3 = new TextBox();

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 415

textBox3->Location = System::Drawing::Point(220, 15); textBox3->Text = “50”; //pActiveDoc->nThinWidth.ToString(); textBox3->TabIndex = 1;

textBox3->Size = System::Drawing::Size(64, 20);

TextBox* textBox4 = new TextBox();

textBox4->Location = System::Drawing::Point(220, 45); textBox4->Text = “25”; //pActiveDoc->nThickWidth.ToString(); textBox4->TabIndex = 2;

textBox4->Size = System::Drawing::Size(64, 20);

Label* label3 = new Label();

label3->Location = System::Drawing::Point(155, 20); label3->Text = “Width:”;

label3->Size = System::Drawing::Size(50, 16); label3->TabIndex = 3;

Label* label4 = new Label();

label4->Location = System::Drawing::Point(155, 50); label4->Text = “Height:”;

label4->Size = System::Drawing::Size(50, 16); label4->TabIndex = 4;

//END

f->FormBorderStyle = FormBorderStyle::FixedDialog;

//Set the MaximizeBox to false to remove the maximize box. f->MaximizeBox = false;

//Set the MinimizeBox to false to remove the minimize box. f->MinimizeBox = false;

//Set the accept button of the form to button1.

f->AcceptButton = button1;

// Set the cancel button of the form to button2. f->CancelButton = button2;

f->StartPosition = FormStartPosition::CenterScreen;

f->Controls->Add(button1);

416 Project 2 CREATING AN APPLICATION USING MANAGED C++

f->Controls->Add(button2); f->Controls->Add(label1); f->Controls->Add(label2); f->Controls->Add(label3); f->Controls->Add(label4); f->Controls->Add(textBox1); f->Controls->Add(textBox2); f->Controls->Add(textBox3); f->Controls->Add(textBox4);

System::Windows::Forms::DialogResult res = f->ShowDialog(); if(res == System::Windows::Forms::DialogResult::OK )

{

pActiveDoc->nShapeLeft = UInt16::Parse(textBox1->Text); pActiveDoc->nShapeTop = UInt16::Parse(textBox2->Text); pActiveDoc->nShapeWidth = UInt16::Parse(textBox3->Text); pActiveDoc->nShapeHeight = UInt16::Parse(textBox4->Text); pActiveView->HandleFilledEllipseDraw();

f->Close();

}

}

void CMainWindow::DrawFilledRect()

{

Form* f = new Form();

//Get the document of active view

CGDIPlusView* pActiveView = dynamic_cast<CGDIPlusView*> (this- >ActiveMdiChild);

CGDIPlusDoc* pActiveDoc = pActiveView->GetDocument();

f->AutoScaleBaseSize = System::Drawing::Size(5, 13);

f->Text = “Draw Filled Rectangle”;

f->ClientSize = System::Drawing::Size(300, 125);

Button* button1 = new Button();

button1->Location = System::Drawing::Point(70, 100); button1->Size = System::Drawing::Size(60, 20);

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 417

button1->TabIndex = 1; button1->Text = “OK”;

button1->DialogResult = System::Windows::Forms::DialogResult::OK ; //Make this “OK” button

Button* button2 = new Button();

button2->Location = System::Drawing::Point(150, 100); button2->Size = System::Drawing::Size(60, 20); button2->TabIndex = 6;

button2->Text = “Cancel”;

//Left

TextBox* textBox1 = new TextBox();

textBox1->Location = System::Drawing::Point(80, 15); textBox1->Text = “10”; //pActiveDoc->nThinWidth.ToString(); textBox1->TabIndex = 1;

textBox1->Size = System::Drawing::Size(64, 20);

//Top

TextBox* textBox2 = new TextBox();

textBox2->Location = System::Drawing::Point(80, 45); textBox2->Text = “10”; //pActiveDoc->nThickWidth.ToString(); textBox2->TabIndex = 2;

textBox2->Size = System::Drawing::Size(64, 20);

Label* label1 = new Label();

label1->Location = System::Drawing::Point(15, 20); label1->Text = “Left:”;

label1->Size = System::Drawing::Size(50, 16); label1->TabIndex = 3;

Label* label2 = new Label();

label2->Location = System::Drawing::Point(15, 50); label2->Text = “Top:”;

label2->Size = System::Drawing::Size(50, 16); label2->TabIndex = 4;

//PSK START

418 Project 2 CREATING AN APPLICATION USING MANAGED C++

TextBox* textBox3 = new TextBox();

textBox3->Location = System::Drawing::Point(220, 15); textBox3->Text = “50”; //pActiveDoc->nThinWidth.ToString(); textBox3->TabIndex = 1;

textBox3->Size = System::Drawing::Size(64, 20);

TextBox* textBox4 = new TextBox();

textBox4->Location = System::Drawing::Point(220, 45); textBox4->Text = “25”; //pActiveDoc->nThickWidth.ToString(); textBox4->TabIndex = 2;

textBox4->Size = System::Drawing::Size(64, 20);

Label* label3 = new Label();

label3->Location = System::Drawing::Point(155, 20); label3->Text = “Width:”;

label3->Size = System::Drawing::Size(50, 16); label3->TabIndex = 3;

Label* label4 = new Label();

label4->Location = System::Drawing::Point(155, 50); label4->Text = “Height:”;

label4->Size = System::Drawing::Size(50, 16); label4->TabIndex = 4;

//END

f->FormBorderStyle = FormBorderStyle::FixedDialog;

//Set the MaximizeBox to false to remove the maximize box. f->MaximizeBox = false;

//Set the MinimizeBox to false to remove the minimize box. f->MinimizeBox = false;

//Set the accept button of the form to button1.

f->AcceptButton = button1;

// Set the cancel button of the form to button2. f->CancelButton = button2;

f->StartPosition = FormStartPosition::CenterScreen;

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 419

f->Controls->Add(button1); f->Controls->Add(button2); f->Controls->Add(label1); f->Controls->Add(label2); f->Controls->Add(label3); f->Controls->Add(label4); f->Controls->Add(textBox1); f->Controls->Add(textBox2); f->Controls->Add(textBox3); f->Controls->Add(textBox4);

System::Windows::Forms::DialogResult res = f->ShowDialog(); if(res == System::Windows::Forms::DialogResult::OK )

{

//Draw Rectangle in the View

pActiveDoc->nShapeLeft = Int16::Parse(textBox1->Text); pActiveDoc->nShapeTop = Int16::Parse(textBox2->Text); pActiveDoc->nShapeWidth = Int16::Parse(textBox3->Text); pActiveDoc->nShapeHeight = Int16::Parse(textBox4->Text); pActiveView->HandleFilledRectDraw();

f->Close();

}

}

//START PSK — Delegates and Events

public __delegate void MyDelegate(int, int); //Declare delegate

//Managed class with virtual event __gc class CMyClass

{

public:

virtual __event MyDelegate *E;

};

//Implement virtual events

__gc class EventSource : public CMyClass

{

public: