📄 gdiplus.cpp
字号:
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;
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 )
{
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);
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
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;
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 Rectange 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:
__event MyDelegate *E;
void Fire_E(int n1, int n2)
{
E(n1, n2);
}
};
// class to hold event handlers, the event receiver
public __gc struct EventReceiver
{
void Add(int num1, int num2)
{
String* pStr;
pStr = String::Format(" {0} + {1} = {2}", Convert::ToString(num1), Convert::ToString(num2), Convert::ToString(num1+num2));
MessageBox::Show(pStr, "Addition");
}
void Subtract(int num1, int num2)
{
String* pStr;
pStr = String::Format(" {0} - {1} = {2}", Convert::ToString(num1), Convert::ToString(num2), Convert::ToString(num1-num2));
MessageBox::Show(pStr, "Subtraction");
}
void Multiply(int num1, int num2)
{
String* pStr;
pStr = String::Format(" {0} * {1} = {2}", Convert::ToString(num1), Convert::ToString(num2), Convert::ToString(num1*num2));
MessageBox::Show(pStr, "Multiplication");
}
void Divide(int num1, int num2)
{
if (num2 == 0)
{
MessageBox::Show("Divide by Zero eror", "Division");
return;
}
String* pStr;
pStr = String::Format(" {0} / {1} = {2} (Rounded)", Convert::ToString(num1), Convert::ToString(num2), Convert::ToString(num1/num2));
MessageBox::Show(pStr, "Division");
}
};
void CMainWindow::HandleDelegate()
{
int nOp = 0;
int nNum1 = 0;
int nNum2 = 0;
String* pOp;
//Simple calculation form
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 = "Simple Calculation";
f->ClientSize = System::Drawing::Size(200, 125);
ComboBox* cmbBox1 = new ComboBox();
cmbBox1->Location = System::Drawing::Point(70, 40);
cmbBox1->Size = System::Drawing::Size(30, 20);
cmbBox1->TabIndex = 2;
cmbBox1->set_DropDownStyle(ComboBoxStyle::DropDownList);
//Add existing operations
cmbBox1->Items->Add(Convert::ToString("+"));
cmbBox1->Items->Add(Convert::ToString("-"));
cmbBox1->Items->Add(Convert::ToString("*"));
cmbBox1->Items->Add(Convert::ToString("/"));
Label* label1 = new Label();
label1->Location = System::Drawing::Point(15, 20);
label1->Text = "Num1:";
label1->Size = System::Drawing::Size(40, 16);
Label* label2 = new Label();
label2->Location = System::Drawing::Point(15, 48);
label2->Text = "Operation:";
label2->Size = System::Drawing::Size(56, 16);
Label* label3 = new Label();
label3->Location = System::Drawing::Point(15, 75);
label3->Text = "Num2:";
label3->Size = System::Drawing::Size(40, 16);
Button* button1 = new Button();
button1->Location = System::Drawing::Point(35, 100);
button1->Size = System::Drawing::Size(60, 20);
button1->TabIndex = 4;
button1->Text = "OK";
button1->DialogResult = System::Windows::Forms::DialogResult::OK ;//Make this "OK" button
Button* button2 = new Button();
button2->Location = System::Drawing::Point(105, 100);
button2->Size = System::Drawing::Size(60, 20);
button2->TabIndex = 5;
button2->Text = "Cancel";
TextBox* textBox1 = new TextBox();
textBox1->Location = System::Drawing::Point(70, 15);
textBox1->TabIndex = 1;
textBox1->Size = System::Drawing::Size(64, 20);
TextBox* textBox2 = new TextBox();
textBox2->Location = System::Drawing::Point(70, 65);
textBox2->TabIndex = 3;
textBox2->Size = System::Drawing::Size(64, 20);
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(cmbBox1);
f->Controls->Add(textBox1);
f->Controls->Add(textBox2);
f->Controls->Add(label1);
f->Controls->Add(label2);
f->Controls->Add(label3);
System::Windows::Forms::DialogResult res = f->ShowDialog();
if(res == System::Windows::Forms::DialogResult::OK )
{
String *pStr1, *pStr2;
pStr1 = textBox1->Text;
pStr1 = pStr1->Trim();
pStr2 = textBox2->Text;
pStr2 = pStr2->Trim();
//Check for Empty values
if (pStr1 == "" || pStr2 == "")
{
MessageBox::Show("Operands missing...", "Message");
return;
}
//Convert Strings to Integers
nNum1 = Convert::ToInt16(pStr1);
nNum2 = Convert::ToInt16(pStr2);
//Get the operand from the Combo box
pOp = cmbBox1->Text;
//Check which operator (+,-,*,/) user has choosen
if (pOp->CompareTo("+") == 0)
nOp=1;
else if (pOp->CompareTo("-") == 0)
nOp=2;
else if (pOp->CompareTo("*") == 0)
nOp=3;
else if (pOp->CompareTo("/") == 0)
nOp=4;
f->Close();
}
EventSource* pE = new EventSource;
EventReceiver* pR = new EventReceiver;
// Add event handlers
if (nOp == 1)
pE->E += new MyDelegate(pR, &EventReceiver::Add);
else if (nOp == 2)
pE->E += new MyDelegate(pR, &EventReceiver::Subtract);
else if (nOp == 3)
pE->E += new MyDelegate(pR, &EventReceiver::Multiply);
else if (nOp == 4)
pE->E += new MyDelegate(pR, &EventReceiver::Divide);
// Raise events
pE->Fire_E(nNum1, nNum2);
}
//Entry point
void main()
{
Application::Run(new CMainWindow());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -