📄 form1.h
字号:
//
this->redToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->redToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"redToolStripButton.Image")));
this->redToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->redToolStripButton->Name = L"redToolStripButton";
this->redToolStripButton->Size = System::Drawing::Size(23, 22);
this->redToolStripButton->Text = L"toolStripButton1";
this->redToolStripButton->ToolTipText = L"Draw in red";
this->redToolStripButton->Click += gcnew System::EventHandler(this, &Form1::redToolStripMenuItem_Click);
//
// greenToolStripButton
//
this->greenToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->greenToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"greenToolStripButton.Image")));
this->greenToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->greenToolStripButton->Name = L"greenToolStripButton";
this->greenToolStripButton->Size = System::Drawing::Size(23, 22);
this->greenToolStripButton->Text = L"toolStripButton1";
this->greenToolStripButton->ToolTipText = L"Draw in green";
this->greenToolStripButton->Click += gcnew System::EventHandler(this, &Form1::greenToolStripMenuItem_Click);
//
// blueToolStripButton
//
this->blueToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->blueToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"blueToolStripButton.Image")));
this->blueToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->blueToolStripButton->Name = L"blueToolStripButton";
this->blueToolStripButton->Size = System::Drawing::Size(23, 22);
this->blueToolStripButton->Text = L"toolStripButton1";
this->blueToolStripButton->ToolTipText = L"Draw in blue";
this->blueToolStripButton->Click += gcnew System::EventHandler(this, &Form1::blueToolStripMenuItem_Click);
//
// toolStripSeparator9
//
this->toolStripSeparator9->Name = L"toolStripSeparator9";
this->toolStripSeparator9->Size = System::Drawing::Size(6, 25);
//
// dashedStripButton
//
this->dashedStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->dashedStripButton->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"dashedStripButton.Image")));
this->dashedStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
this->dashedStripButton->Name = L"dashedStripButton";
this->dashedStripButton->Size = System::Drawing::Size(23, 22);
this->dashedStripButton->Text = L"solidToolStripButton";
this->dashedStripButton->ToolTipText = L"Solid line mode";
this->dashedStripButton->Click += gcnew System::EventHandler(this, &Form1::solidToolStripMenuItem_Click);
//
// toolStripButton2
//
this->toolStripButton2->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton2->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton2.Image")));
this->toolStripButton2->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton2->Name = L"toolStripButton2";
this->toolStripButton2->Size = System::Drawing::Size(23, 22);
this->toolStripButton2->Text = L"dashedToolStripButton";
this->toolStripButton2->ToolTipText = L"Dashed line mode";
this->toolStripButton2->Click += gcnew System::EventHandler(this, &Form1::dashedToolStripMenuItem_Click);
//
// toolStripButton3
//
this->toolStripButton3->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
this->toolStripButton3->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"toolStripButton3.Image")));
this->toolStripButton3->ImageTransparentColor = System::Drawing::Color::Magenta;
this->toolStripButton3->Name = L"toolStripButton3";
this->toolStripButton3->Size = System::Drawing::Size(23, 22);
this->toolStripButton3->Text = L"dottedToolStripButton";
this->toolStripButton3->ToolTipText = L"Dotted line mode";
this->toolStripButton3->Click += gcnew System::EventHandler(this, &Form1::dottedToolStripMenuItem_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(440, 273);
this->Controls->Add(this->toolStrip1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"Form1";
this->Text = L"CLR Sketcher";
this->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseUp);
this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint);
this->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseDown);
this->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseMove);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->toolStrip1->ResumeLayout(false);
this->toolStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void lineToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
elementType = ElementType::LINE; }
private: System::Void rectangleToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
elementType = ElementType::RECTANGLE; }
private: System::Void circleToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
elementType = ElementType::CIRCLE; }
private: System::Void blackToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
color = Color::Black; }
private: System::Void redToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
color = Color::Red; }
private: System::Void greenToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
color = Color::Green; }
private: System::Void blueToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
color = Color::Blue;
}
private: System::Void colorToolStripMenuItem_DropDownOpening(System::Object^ sender, System::EventArgs^ e) {
blackToolStripMenuItem->Checked = color == Color::Black;
redToolStripMenuItem->Checked = color == Color::Red;
greenToolStripMenuItem->Checked = color == Color::Green;
blueToolStripMenuItem->Checked = color == Color::Blue;
}
private: System::Void elementToolStripMenuItem_DropDownOpening(System::Object^ sender, System::EventArgs^ e) {
lineToolStripMenuItem->Checked = elementType == ElementType::LINE;
rectangleToolStripMenuItem->Checked = elementType == ElementType::RECTANGLE;
circleToolStripMenuItem->Checked = elementType == ElementType::CIRCLE;
curveToolStripMenuItem->Checked = elementType == ElementType::CURVE;
ellipseToolStripMenuItem->Checked = elementType == ElementType::ELLIPSE;
}
// Current element type
ElementType elementType;
// Current drawing color
Color color;
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
Graphics^ g = e->Graphics;
if(tempElement)
tempElement->Draw(g);
}
// Records when drawing an element is in progress
bool drawing;
// Records the initial mouse cursor position
Point firstPoint;
private: System::Void Form1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if(e->Button == System::Windows::Forms::MouseButtons::Left)
{
drawing = true;
firstPoint = e->Location;
}
}
private: System::Void Form1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if(drawing)
{
switch(elementType)
{
case ElementType::LINE:
tempElement = gcnew Line(color, lineStyle, firstPoint, e->Location);
break;
case ElementType::RECTANGLE:
tempElement = gcnew Rectangle(color, lineStyle, firstPoint, e->Location);
break;
case ElementType::CIRCLE:
tempElement = gcnew Circle(color, lineStyle, firstPoint, e->Location);
break;
case ElementType::CURVE:
// Code to create a Curve element...
break;
case ElementType::ELLIPSE:
tempElement = gcnew Ellipse(color, lineStyle, firstPoint, e->Location);
break;
}
Invalidate();
}
}
private: System::Void Form1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
if(!drawing)
return;
if(tempElement)
{
// Store the element in the sketch...
tempElement = nullptr;
// Invalidate();
}
drawing = false;
}
// Temporary store for the element being drawn
Element^ tempElement;
private: System::Void ellipseToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
elementType = ElementType::ELLIPSE;
}
// Current line style in effect
LineStyle lineStyle;
private: System::Void solidToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
lineStyle = LineStyle::SOLID;
}
private: System::Void dottedToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
lineStyle = LineStyle::DOTTED;
}
private: System::Void dashedToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
lineStyle = LineStyle::DASHED;
}
private: System::Void lineStyleStripMenuItem_DropDownOpening(System::Object^ sender, System::EventArgs^ e) {
solidToolStripMenuItem->Checked = lineStyle == LineStyle::SOLID;
dottedToolStripMenuItem->Checked = lineStyle == LineStyle::DOTTED;
dashedToolStripMenuItem->Checked = lineStyle == LineStyle::DASHED;
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -