Note that there are some explanatory texts on larger screens.

plurals
  1. POvector use in C++ windows forms
    primarykey
    data
    text
    <p>I'm programming in C++ using Visual Studio 2010 using a Windows Form to create stuff. Friggin' hating it!</p> <p>I want to use vector arrays, which I can do easily enough in a native C++ program but I can't find any walk thru examples for use in a Form.</p> <p>I've included cliext/vector in the main.cpp. If I try and include in the Form.h it tells me I can't do it. When I try and create a vector array variable it tells me I have a </p> <p>syntax error missing ';' before '&lt;'</p> <p>All I want to do is create 6 arrays (int/float/2 Point/2 String^) that I can easily add data too then read it back later.</p> <p>I just need an example of how to set it up.</p> <p>[Edit]</p> <p>Not sure how posting code that doesn't work is going to help in getting a link to a working example but sure... I'll go along with it. </p> <p>Oh, if I add using namespace cliext; at the top of my .h file I'm told that cliext isn't a class or namesapce.</p> <p>The first load of errors are all about how the vector syntax is wrong...then I get a load of errors stemming from the variables being undefined later on.</p> <pre><code>#pragma once namespace Lab6_Draw_V1 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// &lt;summary&gt; /// Summary for Form1 /// &lt;/summary&gt; public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here iPix=1; sColorLine="Black"; sColor="Black"; // } protected: /// &lt;summary&gt; /// Clean up any resources being used. /// &lt;/summary&gt; ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Panel^ panel1; protected: private: System::Windows::Forms::ColorDialog^ colorDialog1; private: System::Windows::Forms::Label^ colorBox1; private: System::Windows::Forms::RadioButton^ BtnPix1; private: System::Windows::Forms::RadioButton^ BtnPix3; private: System::Windows::Forms::RadioButton^ BtnPix5; private: System::Windows::Forms::ToolStrip^ toolStrip1; private: System::Windows::Forms::ToolStripButton^ toolStripBtnLine; private: System::Windows::Forms::ToolStripButton^ toolStripBtnSquare; private: System::Windows::Forms::ToolStripButton^ toolStripBtnEllipse; private: System::Windows::Forms::ToolStripButton^ toolStripBtnColor; private: System::Windows::Forms::Label^ labelPos1; private: System::Windows::Forms::Label^ labelPos2; private: /// &lt;summary&gt; /// Required designer variable. Point firstPoint,finalPoint,iSize; bool Drawing,move; int iShape; float iPix; String^ sColor; String^ sColorLine; vector&lt;int&gt; vShape; vector&lt;Point&gt; vfirstPoint; vector&lt;Point&gt; vSize; vector&lt;float&gt; vPix; vector&lt;String^&gt;^ vfillColor; vector&lt;String^&gt;^ vlineColor; private: System::Windows::Forms::RadioButton^ BtnPix7; private: System::Windows::Forms::RadioButton^ BtnPix10; private: System::Windows::Forms::RadioButton^ BtnPix15; private: System::Windows::Forms::Panel^ panel2; private: System::Windows::Forms::ToolStripButton^ toolStripBtnLineColor; private: System::Windows::Forms::Label^ colorBox2; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::Label^ label2; /// &lt;/summary&gt; System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// &lt;summary&gt; /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// &lt;/summary&gt; void InitializeComponent(void) { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); this-&gt;panel1 = (gcnew System::Windows::Forms::Panel()); this-&gt;colorDialog1 = (gcnew System::Windows::Forms::ColorDialog()); this-&gt;colorBox1 = (gcnew System::Windows::Forms::Label()); this-&gt;BtnPix1 = (gcnew System::Windows::Forms::RadioButton()); this-&gt;BtnPix3 = (gcnew System::Windows::Forms::RadioButton()); this-&gt;BtnPix5 = (gcnew System::Windows::Forms::RadioButton()); this-&gt;toolStrip1 = (gcnew System::Windows::Forms::ToolStrip()); this-&gt;toolStripBtnLine = (gcnew System::Windows::Forms::ToolStripButton()); this-&gt;toolStripBtnSquare = (gcnew System::Windows::Forms::ToolStripButton()); this-&gt;toolStripBtnEllipse = (gcnew System::Windows::Forms::ToolStripButton()); this-&gt;toolStripBtnColor = (gcnew System::Windows::Forms::ToolStripButton()); this-&gt;toolStripBtnLineColor = (gcnew System::Windows::Forms::ToolStripButton()); this-&gt;labelPos1 = (gcnew System::Windows::Forms::Label()); this-&gt;labelPos2 = (gcnew System::Windows::Forms::Label()); this-&gt;BtnPix7 = (gcnew System::Windows::Forms::RadioButton()); this-&gt;BtnPix10 = (gcnew System::Windows::Forms::RadioButton()); this-&gt;BtnPix15 = (gcnew System::Windows::Forms::RadioButton()); this-&gt;panel2 = (gcnew System::Windows::Forms::Panel()); this-&gt;colorBox2 = (gcnew System::Windows::Forms::Label()); this-&gt;label1 = (gcnew System::Windows::Forms::Label()); this-&gt;label2 = (gcnew System::Windows::Forms::Label()); this-&gt;toolStrip1-&gt;SuspendLayout(); this-&gt;SuspendLayout(); // // panel1 // this-&gt;panel1-&gt;BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D; this-&gt;panel1-&gt;Location = System::Drawing::Point(160, 37); this-&gt;panel1-&gt;Name = L"panel1"; this-&gt;panel1-&gt;Size = System::Drawing::Size(837, 447); this-&gt;panel1-&gt;TabIndex = 0; this-&gt;panel1-&gt;Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &amp;Form1::panel1_Paint); this-&gt;panel1-&gt;MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &amp;Form1::panel1_MouseDown); this-&gt;panel1-&gt;MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &amp;Form1::panel1_MouseMove); this-&gt;panel1-&gt;MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &amp;Form1::panel1_MouseUp); // // colorBox1 // this-&gt;colorBox1-&gt;AutoSize = true; this-&gt;colorBox1-&gt;BackColor = System::Drawing::Color::White; this-&gt;colorBox1-&gt;BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D; this-&gt;colorBox1-&gt;Location = System::Drawing::Point(16, 148); this-&gt;colorBox1-&gt;MinimumSize = System::Drawing::Size(37, 37); this-&gt;colorBox1-&gt;Name = L"colorBox1"; this-&gt;colorBox1-&gt;Size = System::Drawing::Size(37, 37); this-&gt;colorBox1-&gt;TabIndex = 6; this-&gt;colorBox1-&gt;BackColorChanged += gcnew System::EventHandler(this, &amp;Form1::colorBox1_BackColorChanged); // // BtnPix1 // this-&gt;BtnPix1-&gt;AutoSize = true; this-&gt;BtnPix1-&gt;Checked = true; this-&gt;BtnPix1-&gt;Location = System::Drawing::Point(83, 213); this-&gt;BtnPix1-&gt;Name = L"BtnPix1"; this-&gt;BtnPix1-&gt;Size = System::Drawing::Size(56, 17); this-&gt;BtnPix1-&gt;TabIndex = 7; this-&gt;BtnPix1-&gt;TabStop = true; this-&gt;BtnPix1-&gt;Text = L"1 Pixel"; this-&gt;BtnPix1-&gt;UseVisualStyleBackColor = true; this-&gt;BtnPix1-&gt;CheckedChanged += gcnew System::EventHandler(this, &amp;Form1::BtnPix1_CheckedChanged); // // BtnPix3 // this-&gt;BtnPix3-&gt;AutoSize = true; this-&gt;BtnPix3-&gt;Location = System::Drawing::Point(83, 236); this-&gt;BtnPix3-&gt;Name = L"BtnPix3"; this-&gt;BtnPix3-&gt;Size = System::Drawing::Size(56, 17); this-&gt;BtnPix3-&gt;TabIndex = 8; this-&gt;BtnPix3-&gt;Text = L"3 Pixel"; this-&gt;BtnPix3-&gt;UseVisualStyleBackColor = true; this-&gt;BtnPix3-&gt;CheckedChanged += gcnew System::EventHandler(this, &amp;Form1::BtnPix3_CheckedChanged); // // BtnPix5 // this-&gt;BtnPix5-&gt;AutoSize = true; this-&gt;BtnPix5-&gt;Location = System::Drawing::Point(83, 259); this-&gt;BtnPix5-&gt;Name = L"BtnPix5"; this-&gt;BtnPix5-&gt;Size = System::Drawing::Size(56, 17); this-&gt;BtnPix5-&gt;TabIndex = 9; this-&gt;BtnPix5-&gt;Text = L"5 Pixel"; this-&gt;BtnPix5-&gt;UseVisualStyleBackColor = true; this-&gt;BtnPix5-&gt;CheckedChanged += gcnew System::EventHandler(this, &amp;Form1::BtnPix5_CheckedChanged); // // toolStrip1 // this-&gt;toolStrip1-&gt;Items-&gt;AddRange(gcnew cli::array&lt; System::Windows::Forms::ToolStripItem^ &gt;(5) {this-&gt;toolStripBtnLine, this-&gt;toolStripBtnSquare, this-&gt;toolStripBtnEllipse, this-&gt;toolStripBtnColor, this-&gt;toolStripBtnLineColor}); this-&gt;toolStrip1-&gt;Location = System::Drawing::Point(0, 0); this-&gt;toolStrip1-&gt;Name = L"toolStrip1"; this-&gt;toolStrip1-&gt;Size = System::Drawing::Size(1016, 25); this-&gt;toolStrip1-&gt;TabIndex = 10; this-&gt;toolStrip1-&gt;Text = L"toolStrip1"; this-&gt;toolStrip1-&gt;ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &amp;Form1::toolStrip1_ItemClicked); // // toolStripBtnLine // this-&gt;toolStripBtnLine-&gt;DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text; this-&gt;toolStripBtnLine-&gt;Image = (cli::safe_cast&lt;System::Drawing::Image^ &gt;(resources-&gt;GetObject(L"toolStripBtnLine.Image"))); this-&gt;toolStripBtnLine-&gt;ImageTransparentColor = System::Drawing::Color::Magenta; this-&gt;toolStripBtnLine-&gt;Name = L"toolStripBtnLine"; this-&gt;toolStripBtnLine-&gt;Size = System::Drawing::Size(33, 22); this-&gt;toolStripBtnLine-&gt;Text = L"Line"; this-&gt;toolStripBtnLine-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::toolStripBtnLine_Click); // // toolStripBtnSquare // this-&gt;toolStripBtnSquare-&gt;DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text; this-&gt;toolStripBtnSquare-&gt;Image = (cli::safe_cast&lt;System::Drawing::Image^ &gt;(resources-&gt;GetObject(L"toolStripBtnSquare.Image"))); this-&gt;toolStripBtnSquare-&gt;ImageTransparentColor = System::Drawing::Color::Magenta; this-&gt;toolStripBtnSquare-&gt;Name = L"toolStripBtnSquare"; this-&gt;toolStripBtnSquare-&gt;Size = System::Drawing::Size(47, 22); this-&gt;toolStripBtnSquare-&gt;Text = L"Square"; this-&gt;toolStripBtnSquare-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::toolStripBtnSquare_Click); // // toolStripBtnEllipse // this-&gt;toolStripBtnEllipse-&gt;DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text; this-&gt;toolStripBtnEllipse-&gt;Image = (cli::safe_cast&lt;System::Drawing::Image^ &gt;(resources-&gt;GetObject(L"toolStripBtnEllipse.Image"))); this-&gt;toolStripBtnEllipse-&gt;ImageTransparentColor = System::Drawing::Color::Magenta; this-&gt;toolStripBtnEllipse-&gt;Name = L"toolStripBtnEllipse"; this-&gt;toolStripBtnEllipse-&gt;Size = System::Drawing::Size(44, 22); this-&gt;toolStripBtnEllipse-&gt;Text = L"Ellipse"; this-&gt;toolStripBtnEllipse-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::toolStripBtnEllipse_Click); // // toolStripBtnColor // this-&gt;toolStripBtnColor-&gt;DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text; this-&gt;toolStripBtnColor-&gt;Image = (cli::safe_cast&lt;System::Drawing::Image^ &gt;(resources-&gt;GetObject(L"toolStripBtnColor.Image"))); this-&gt;toolStripBtnColor-&gt;ImageTransparentColor = System::Drawing::Color::Magenta; this-&gt;toolStripBtnColor-&gt;Name = L"toolStripBtnColor"; this-&gt;toolStripBtnColor-&gt;Size = System::Drawing::Size(58, 22); this-&gt;toolStripBtnColor-&gt;Text = L"Fill Color"; this-&gt;toolStripBtnColor-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::toolStripBtnColor_Click); // // toolStripBtnLineColor // this-&gt;toolStripBtnLineColor-&gt;DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text; this-&gt;toolStripBtnLineColor-&gt;Image = (cli::safe_cast&lt;System::Drawing::Image^ &gt;(resources-&gt;GetObject(L"toolStripBtnLineColor.Image"))); this-&gt;toolStripBtnLineColor-&gt;ImageTransparentColor = System::Drawing::Color::Magenta; this-&gt;toolStripBtnLineColor-&gt;Name = L"toolStripBtnLineColor"; this-&gt;toolStripBtnLineColor-&gt;Size = System::Drawing::Size(65, 22); this-&gt;toolStripBtnLineColor-&gt;Text = L"Line Color"; this-&gt;toolStripBtnLineColor-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::toolStripBtnLineColor_Click); // // labelPos1 // this-&gt;labelPos1-&gt;AutoSize = true; this-&gt;labelPos1-&gt;Location = System::Drawing::Point(712, 504); this-&gt;labelPos1-&gt;Name = L"labelPos1"; this-&gt;labelPos1-&gt;Size = System::Drawing::Size(35, 13); this-&gt;labelPos1-&gt;TabIndex = 11; this-&gt;labelPos1-&gt;Text = L"label1"; // // labelPos2 // this-&gt;labelPos2-&gt;AutoSize = true; this-&gt;labelPos2-&gt;Location = System::Drawing::Point(848, 504); this-&gt;labelPos2-&gt;Name = L"labelPos2"; this-&gt;labelPos2-&gt;Size = System::Drawing::Size(35, 13); this-&gt;labelPos2-&gt;TabIndex = 12; this-&gt;labelPos2-&gt;Text = L"label2"; // // BtnPix7 // this-&gt;BtnPix7-&gt;AutoSize = true; this-&gt;BtnPix7-&gt;Location = System::Drawing::Point(83, 282); this-&gt;BtnPix7-&gt;Name = L"BtnPix7"; this-&gt;BtnPix7-&gt;Size = System::Drawing::Size(56, 17); this-&gt;BtnPix7-&gt;TabIndex = 13; this-&gt;BtnPix7-&gt;Text = L"7 Pixel"; this-&gt;BtnPix7-&gt;UseVisualStyleBackColor = true; this-&gt;BtnPix7-&gt;CheckedChanged += gcnew System::EventHandler(this, &amp;Form1::BtnPix7_CheckedChanged); // // BtnPix10 // this-&gt;BtnPix10-&gt;AutoSize = true; this-&gt;BtnPix10-&gt;Location = System::Drawing::Point(83, 306); this-&gt;BtnPix10-&gt;Name = L"BtnPix10"; this-&gt;BtnPix10-&gt;Size = System::Drawing::Size(62, 17); this-&gt;BtnPix10-&gt;TabIndex = 14; this-&gt;BtnPix10-&gt;Text = L"10 Pixel"; this-&gt;BtnPix10-&gt;UseVisualStyleBackColor = true; this-&gt;BtnPix10-&gt;CheckedChanged += gcnew System::EventHandler(this, &amp;Form1::BtnPix10_CheckedChanged); // // BtnPix15 // this-&gt;BtnPix15-&gt;AutoSize = true; this-&gt;BtnPix15-&gt;Location = System::Drawing::Point(83, 329); this-&gt;BtnPix15-&gt;Name = L"BtnPix15"; this-&gt;BtnPix15-&gt;Size = System::Drawing::Size(62, 17); this-&gt;BtnPix15-&gt;TabIndex = 15; this-&gt;BtnPix15-&gt;Text = L"15 Pixel"; this-&gt;BtnPix15-&gt;UseVisualStyleBackColor = true; this-&gt;BtnPix15-&gt;CheckedChanged += gcnew System::EventHandler(this, &amp;Form1::BtnPix15_CheckedChanged); // // panel2 // this-&gt;panel2-&gt;BackColor = System::Drawing::Color::White; this-&gt;panel2-&gt;BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D; this-&gt;panel2-&gt;Location = System::Drawing::Point(83, 148); this-&gt;panel2-&gt;Name = L"panel2"; this-&gt;panel2-&gt;Size = System::Drawing::Size(37, 37); this-&gt;panel2-&gt;TabIndex = 17; // // colorBox2 // this-&gt;colorBox2-&gt;AutoSize = true; this-&gt;colorBox2-&gt;BackColor = System::Drawing::Color::Black; this-&gt;colorBox2-&gt;BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D; this-&gt;colorBox2-&gt;Location = System::Drawing::Point(16, 213); this-&gt;colorBox2-&gt;MinimumSize = System::Drawing::Size(37, 37); this-&gt;colorBox2-&gt;Name = L"colorBox2"; this-&gt;colorBox2-&gt;Size = System::Drawing::Size(37, 37); this-&gt;colorBox2-&gt;TabIndex = 18; this-&gt;colorBox2-&gt;BackColorChanged += gcnew System::EventHandler(this, &amp;Form1::colorBox2_BackColorChanged); // // label1 // this-&gt;label1-&gt;AutoSize = true; this-&gt;label1-&gt;Location = System::Drawing::Point(8, 250); this-&gt;label1-&gt;Name = L"label1"; this-&gt;label1-&gt;Size = System::Drawing::Size(54, 13); this-&gt;label1-&gt;TabIndex = 19; this-&gt;label1-&gt;Text = L"Line Color"; // // label2 // this-&gt;label2-&gt;AutoSize = true; this-&gt;label2-&gt;Location = System::Drawing::Point(12, 185); this-&gt;label2-&gt;Name = L"label2"; this-&gt;label2-&gt;Size = System::Drawing::Size(46, 13); this-&gt;label2-&gt;TabIndex = 20; this-&gt;label2-&gt;Text = L"Fill Color"; // // Form1 // this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13); this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this-&gt;BackColor = System::Drawing::SystemColors::Control; this-&gt;ClientSize = System::Drawing::Size(1016, 538); this-&gt;Controls-&gt;Add(this-&gt;label2); this-&gt;Controls-&gt;Add(this-&gt;label1); this-&gt;Controls-&gt;Add(this-&gt;colorBox2); this-&gt;Controls-&gt;Add(this-&gt;panel2); this-&gt;Controls-&gt;Add(this-&gt;BtnPix15); this-&gt;Controls-&gt;Add(this-&gt;BtnPix10); this-&gt;Controls-&gt;Add(this-&gt;BtnPix7); this-&gt;Controls-&gt;Add(this-&gt;labelPos2); this-&gt;Controls-&gt;Add(this-&gt;labelPos1); this-&gt;Controls-&gt;Add(this-&gt;toolStrip1); this-&gt;Controls-&gt;Add(this-&gt;BtnPix5); this-&gt;Controls-&gt;Add(this-&gt;BtnPix3); this-&gt;Controls-&gt;Add(this-&gt;BtnPix1); this-&gt;Controls-&gt;Add(this-&gt;colorBox1); this-&gt;Controls-&gt;Add(this-&gt;panel1); this-&gt;Icon = (cli::safe_cast&lt;System::Drawing::Icon^ &gt;(resources-&gt;GetObject(L"$this.Icon"))); this-&gt;MinimumSize = System::Drawing::Size(1024, 530); this-&gt;Name = L"Form1"; this-&gt;Text = L"Lab 6 Paint"; this-&gt;toolStrip1-&gt;ResumeLayout(false); this-&gt;toolStrip1-&gt;PerformLayout(); this-&gt;ResumeLayout(false); this-&gt;PerformLayout(); } #pragma endregion private: System::Void btnColor_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { // Loop with case statements for the shapes and colours // grab data from vector array } private: System::Void toolStripBtnColor_Click(System::Object^ sender, System::EventArgs^ e) { ColorDialog^ MyDialog = gcnew ColorDialog; // Keeps the user from selecting a custom color. MyDialog-&gt;AllowFullOpen = false; // Allows the user to get help. (The default is false.) MyDialog-&gt;ShowHelp = true; // Sets the initial color select to the current text color. MyDialog-&gt;Color = panel1-&gt;ForeColor; // Update the text box color if the user clicks OK if ( MyDialog-&gt;ShowDialog() == ::System::Windows::Forms::DialogResult::OK ) { colorBox1-&gt;BackColor= MyDialog-&gt;Color; sColor = Convert::ToString(colorBox1-&gt;BackColor); // labelColor-&gt;Text=sColor; } } private: System::Void panel1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { if( e-&gt;Button== System::Windows::Forms::MouseButtons::Left) { Drawing = true; firstPoint = e-&gt;Location; labelPos1-&gt;Text = Convert::ToString(e-&gt;Location); // set shape flag } if( e-&gt;Button== System::Windows::Forms::MouseButtons::Right) { move=true; iSize.X=finalPoint.X-firstPoint.X; iSize.Y=finalPoint.Y-firstPoint.Y; } } private: System::Void toolStrip1_ItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e) { } private: System::Void panel1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { </code></pre> <p>// tempPos=e->Location; labelPos2->Text = Convert::ToString(e->Location);</p> <pre><code> if(Drawing) { //draw temp outline with no fill and black outline panel1-&gt;Refresh(); auto g = panel1-&gt;CreateGraphics(); switch(iShape) { case 1: g-&gt;DrawLine(Pens::Black,firstPoint,e-&gt;Location); break; case 2: g-&gt;DrawRectangle(Pens::Black,firstPoint.X,firstPoint.Y,(e-&gt;Location.X-firstPoint.X),(e-&gt;Location.Y-firstPoint.Y)); break; case 3: g-&gt;DrawEllipse(Pens::Black,firstPoint.X,firstPoint.Y,(e-&gt;Location.X-firstPoint.X),(e-&gt;Location.Y-firstPoint.Y)); default:break; } } if(move) { //code panel1-&gt;Refresh(); auto g = panel1-&gt;CreateGraphics(); firstPoint=e-&gt;Location; SolidBrush^ myBrush = gcnew SolidBrush(Color::FromArgb(colorBox1-&gt;BackColor.A,colorBox1-&gt;BackColor.R,colorBox1-&gt;BackColor.G,colorBox1-&gt;BackColor.B) ); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; switch(iShape) { case 1: finalPoint.X=iSize.X+firstPoint.X; finalPoint.Y=iSize.Y+firstPoint.Y; g-&gt;DrawLine(myPen,firstPoint,finalPoint); break; case 2: g-&gt;FillRectangle(myBrush,firstPoint.X,firstPoint.Y,iSize.X,iSize.Y); g-&gt;DrawRectangle(myPen,firstPoint.X,firstPoint.Y,iSize.X,iSize.Y); break; case 3: g-&gt;FillEllipse(myBrush,firstPoint.X,firstPoint.Y,iSize.X,iSize.Y); g-&gt;DrawEllipse(myPen,firstPoint.X,firstPoint.Y,iSize.X,iSize.Y); break; default:break; } } } private: System::Void panel1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { if( e-&gt;Button== System::Windows::Forms::MouseButtons::Left) { finalPoint = e-&gt;Location; labelPos2-&gt;Text = Convert::ToString(e-&gt;Location); // draw filled shape panel1-&gt;Refresh(); auto g = panel1-&gt;CreateGraphics(); SolidBrush^ myBrush = gcnew SolidBrush(Color::FromArgb(colorBox1-&gt;BackColor.A,colorBox1-&gt;BackColor.R,colorBox1-&gt;BackColor.G,colorBox1-&gt;BackColor.B) ); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; switch(iShape) { case 1: g-&gt;DrawLine(myPen,firstPoint,finalPoint); break; case 2: g-&gt;FillRectangle(myBrush,firstPoint.X,firstPoint.Y,(e-&gt;Location.X-firstPoint.X),(e-&gt;Location.Y-firstPoint.Y)); g-&gt;DrawRectangle(myPen,firstPoint.X,firstPoint.Y,(e-&gt;Location.X-firstPoint.X),(e-&gt;Location.Y-firstPoint.Y)); break; case 3: g-&gt;FillEllipse(myBrush,firstPoint.X,firstPoint.Y,(e-&gt;Location.X-firstPoint.X),(e-&gt;Location.Y-firstPoint.Y)); g-&gt;DrawEllipse(myPen,firstPoint.X,firstPoint.Y,(e-&gt;Location.X-firstPoint.X),(e-&gt;Location.Y-firstPoint.Y)); break; default:break; } iSize.X=finalPoint.X-firstPoint.X; iSzie.Y=finalPoint.Y-firstPoint.Y; vShape.push_back (iShape); vfirstPoint.push_back (firstPoint); vSize.push_back (iSize); vfillColor.push_back (myBrush); vlineColor.push_back (myPen); vPix.push_back (iPix); Drawing=false; } else move=false; } private: System::Void toolStripBtnLine_Click(System::Object^ sender, System::EventArgs^ e) { iShape=1; } private: System::Void toolStripBtnSquare_Click(System::Object^ sender, System::EventArgs^ e) { iShape=2; } private: System::Void toolStripBtnEllipse_Click(System::Object^ sender, System::EventArgs^ e) { iShape=3; } private: System::Void BtnPix1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { iPix=1; panel2-&gt;Refresh(); auto g = panel2-&gt;CreateGraphics(); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; g-&gt;DrawLine(myPen,2,18,33,18); } private: System::Void BtnPix3_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { iPix=3; panel2-&gt;Refresh(); auto g = panel2-&gt;CreateGraphics(); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; g-&gt;DrawLine(myPen,2,18,33,18); } private: System::Void BtnPix5_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { iPix=5; panel2-&gt;Refresh(); auto g = panel2-&gt;CreateGraphics(); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; g-&gt;DrawLine(myPen,2,18,33,18); } private: System::Void BtnPix7_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { iPix=7; panel2-&gt;Refresh(); auto g = panel2-&gt;CreateGraphics(); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; g-&gt;DrawLine(myPen,2,18,33,18); } private: System::Void BtnPix10_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { iPix=10; panel2-&gt;Refresh(); auto g = panel2-&gt;CreateGraphics(); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; g-&gt;DrawLine(myPen,2,18,33,18); } private: System::Void BtnPix15_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { iPix=15; panel2-&gt;Refresh(); auto g = panel2-&gt;CreateGraphics(); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; g-&gt;DrawLine(myPen,2,18,33,18); } private: System::Void toolStripBtnLineColor_Click(System::Object^ sender, System::EventArgs^ e) { ColorDialog^ MyDialog = gcnew ColorDialog; // Keeps the user from selecting a custom color. MyDialog-&gt;AllowFullOpen = false; // Allows the user to get help. (The default is false.) MyDialog-&gt;ShowHelp = true; // Sets the initial color select to the current text color. MyDialog-&gt;Color = colorBox2-&gt;BackColor; // Update the text box color if the user clicks OK if ( MyDialog-&gt;ShowDialog() == ::System::Windows::Forms::DialogResult::OK ) { sColorLine = Convert::ToString(MyDialog-&gt;Color); // labelColorLine-&gt;Text=sColorLine; colorBox2-&gt;BackColor= MyDialog-&gt;Color; } } private: System::Void colorBox1_BackColorChanged(System::Object^ sender, System::EventArgs^ e) { panel1-&gt;Refresh(); auto g = panel1-&gt;CreateGraphics(); SolidBrush^ myBrush = gcnew SolidBrush(Color::FromArgb(colorBox1-&gt;BackColor.A,colorBox1-&gt;BackColor.R,colorBox1-&gt;BackColor.G,colorBox1-&gt;BackColor.B) ); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; switch(iShape) { case 1: g-&gt;DrawLine(myPen,firstPoint,finalPoint); break; case 2: g-&gt;FillRectangle(myBrush,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y)); g-&gt;DrawRectangle(myPen,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y)); break; case 3: g-&gt;FillEllipse(myBrush,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y)); g-&gt;DrawEllipse(myPen,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y)); break; default:break; } } private: System::Void colorBox2_BackColorChanged(System::Object^ sender, System::EventArgs^ e) { panel1-&gt;Refresh(); auto g = panel1-&gt;CreateGraphics(); SolidBrush^ myBrush = gcnew SolidBrush(Color::FromArgb(colorBox1-&gt;BackColor.A,colorBox1-&gt;BackColor.R,colorBox1-&gt;BackColor.G,colorBox1-&gt;BackColor.B) ); Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2-&gt;BackColor.A,colorBox2-&gt;BackColor.R,colorBox2-&gt;BackColor.G,colorBox2-&gt;BackColor.B) ); myPen-&gt;Width = iPix; switch(iShape) { case 1: g-&gt;DrawLine(myPen,firstPoint,finalPoint); break; case 2: g-&gt;FillRectangle(myBrush,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y)); g-&gt;DrawRectangle(myPen,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y)); break; case 3: g-&gt;FillEllipse(myBrush,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y)); g-&gt;DrawEllipse(myPen,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y)); break; default:break; } } </code></pre> <p>}; }</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload