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

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

.pdf
Скачиваний:
168
Добавлен:
24.05.2014
Размер:
25.78 Mб
Скачать

400 Project 2 CREATING AN APPLICATION USING MANAGED C++

textBox1->TabIndex = 1;

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

TextBox* textBox2 = new TextBox();

textBox2->Location = System::Drawing::Point(120, 76);

textBox2->Text = pActiveDoc->nThickWidth.ToString();

textBox2->TabIndex = 2;

 

 

 

Y

textBox2->Size =

 

 

 

 

 

 

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

 

 

 

 

 

L

 

Label* label1 = new Label();

F

 

label1->Location =

System::Drawing::Point(16, 36);

 

 

 

M

 

 

label1->Text = “Thin Pen Width:”;

 

 

 

label1->Size =

System::Drawing::Size(88, 16);

 

label1->TabIndex = 3;

 

 

 

 

 

 

E

 

 

 

 

T

 

 

 

 

 

Label* label2 = new Label();

 

 

 

 

label2->Location =

System::Drawing::Point(16,A

76);

label2->Text = “ hick Pen Width:”;

 

 

 

label2->Size =

System::Drawing::Size(95, 16);

 

label2->TabIndex = 4;

 

 

 

 

 

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); f->Controls->Add(label1); f->Controls->Add(label2); f->Controls->Add(textBox1);

Team-Fly®

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 401

f->Controls->Add(textBox2);

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

if(res == System::Windows::Forms::DialogResult::OK )

{

pActiveDoc->nThinWidth = UInt32::Parse(textBox1->Text); pActiveDoc->nThickWidth = UInt32::Parse(textBox2->Text); pActiveDoc->ReplacePen();

f->Close();

}

}

//Disable the menu and toolbar items when there is no active child form void CMainWindow::DisableItems()

{

this->pEditMenuItem->Visible=false; this->pPenMenuItem->Visible=false; this->pWindowMenuItem->Visible=false; this->pCloseMenuItem->Visible=false; this->pSaveMenuItem->Visible=false; this->pSaveAsMenuItem->Visible=false; this->pPrintMenuItem->Visible=false; this->pPrintPreviewMenuItem->Visible=false; this->pSaveTBButton->Enabled = false; this->pPreviewTBButton->Enabled=false; this->pPrintTBButton->Enabled=false;

}

//Enable the menu and toolbar items when the first child form is created void CMainWindow::EnableItems()

{

this->pEditMenuItem->Visible=true; this->pPenMenuItem->Visible=true; this->pWindowMenuItem->Visible=true; this->pCloseMenuItem->Visible=true; this->pSaveMenuItem->Visible=true; this->pSaveAsMenuItem->Visible=true;

402 Project 2 CREATING AN APPLICATION USING MANAGED C++

this->pPrintMenuItem->Visible=true; this->pPrintPreviewMenuItem->Visible=true; this->pSaveTBButton->Enabled = true; this->pPreviewTBButton->Enabled=true; this->pPrintTBButton->Enabled=true;

}

//Creates a new document

CGDIPlusDoc* CMainWindow::CreateDocument()

{

CGDIPlusDoc* pNewDoc = new CGDIPlusDoc (pParentWindow); nDocCount++;

return pNewDoc;

}

void CMainWindow::DrawEllipse()

{

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 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;

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);

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 403

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();

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();

404 Project 2 CREATING AN APPLICATION USING MANAGED C++

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); f->Controls->Add(button2); f->Controls->Add(label1); f->Controls->Add(label2); f->Controls->Add(label3); f->Controls->Add(label4); f->Controls->Add(textBox1);

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 405

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->HandleEllipseDraw();

f->Close();

}

}

void CMainWindow::DrawRect()

{

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 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); 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);

406 Project 2 CREATING AN APPLICATION USING MANAGED C++

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();

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();

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 407

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); f->Controls->Add(button2); f->Controls->Add(label1); f->Controls->Add(label2); f->Controls->Add(label3); f->Controls->Add(label4); f->Controls->Add(textBox1);

408 Project 2 CREATING AN APPLICATION USING MANAGED C++

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 a 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->HandleRectDraw();

f->Close();

}

}

void CMainWindow::DrawText()

{

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 String”;

f->ClientSize = System::Drawing::Size(200, 140);

Button* button1 = new Button();

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

button1->Text = “OK”;

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

CREATING A MANAGED EXTENSIONS APPLICATION Chapter 12 409

Button* button2 = new Button();

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

button2->Text = “Cancel”;

TextBox* textBox1 = new TextBox();

textBox1->Location = System::Drawing::Point(15, 40); textBox1->TabIndex = 1;

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

Label* label1 = new Label();

label1->Location = System::Drawing::Point(15, 20); label1->Text = “Please Enter the text:”; label1->Size = System::Drawing::Size(130, 16); label1->TabIndex = 3;

f->FormBorderStyle = FormBorderStyle::FixedDialog; f->MaximizeBox = false;

f->MinimizeBox = false; f->AcceptButton = button1; f->CancelButton = button2;

f->StartPosition = FormStartPosition::CenterScreen;

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

String* pstrText;

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

{

pstrText = textBox1->Text; f->Close();

}