1

我正在使用 Visual Studio 2010 使用 Windows 窗体在 C++ 中进行编程来创建东西。他妈的讨厌它!

我想使用向量数组,我可以在本机 C++ 程序中轻松做到这一点,但我找不到任何可在表单中使用的遍历示例。

我在 main.cpp 中包含了 cliext/vector。如果我尝试将其包含在 Form.h 中,它会告诉我我做不到。当我尝试创建一个向量数组变量时,它告诉我我有一个

语法错误缺少';' 在'<'之前

我要做的就是创建 6 个数组(int/float/2 Point/2 String^),我也可以轻松添加数据,然后稍后再读回来。

我只需要一个如何设置它的示例。

[编辑]

不确定发布不起作用的代码将如何帮助获得指向工作示例的链接,但可以肯定......我会同意的。

哦,如果我添加 using namespace cliext; 在我的 .h 文件的顶部,我被告知 cliext 不是类或命名空间。

第一次加载的错误都是关于向量语法是如何错误的……然后我得到了一大堆错误,这些错误源于后来未定义的变量。

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


/// <summary>
/// Summary for Form1
/// </summary>
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:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~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:
    /// <summary>
    /// Required designer variable.
    Point firstPoint,finalPoint,iSize;
    bool Drawing,move;
    int iShape;
    float iPix;
    String^ sColor;
    String^ sColorLine;

    vector<int> vShape;
    vector<Point> vfirstPoint;
    vector<Point> vSize;
    vector<float> vPix;
    vector<String^>^ vfillColor;
    vector<String^>^ 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;







    /// </summary>
    System::ComponentModel::Container ^components;

      #pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
        this->panel1 = (gcnew System::Windows::Forms::Panel());
        this->colorDialog1 = (gcnew System::Windows::Forms::ColorDialog());
        this->colorBox1 = (gcnew System::Windows::Forms::Label());
        this->BtnPix1 = (gcnew System::Windows::Forms::RadioButton());
        this->BtnPix3 = (gcnew System::Windows::Forms::RadioButton());
        this->BtnPix5 = (gcnew System::Windows::Forms::RadioButton());
        this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
        this->toolStripBtnLine = (gcnew         System::Windows::Forms::ToolStripButton());
        this->toolStripBtnSquare = (gcnew System::Windows::Forms::ToolStripButton());
        this->toolStripBtnEllipse = (gcnew System::Windows::Forms::ToolStripButton());
        this->toolStripBtnColor = (gcnew System::Windows::Forms::ToolStripButton());
        this->toolStripBtnLineColor = (gcnew System::Windows::Forms::ToolStripButton());
        this->labelPos1 = (gcnew System::Windows::Forms::Label());
        this->labelPos2 = (gcnew System::Windows::Forms::Label());
        this->BtnPix7 = (gcnew System::Windows::Forms::RadioButton());
        this->BtnPix10 = (gcnew System::Windows::Forms::RadioButton());
        this->BtnPix15 = (gcnew System::Windows::Forms::RadioButton());
        this->panel2 = (gcnew System::Windows::Forms::Panel());
        this->colorBox2 = (gcnew System::Windows::Forms::Label());
        this->label1 = (gcnew System::Windows::Forms::Label());
        this->label2 = (gcnew System::Windows::Forms::Label());
        this->toolStrip1->SuspendLayout();
        this->SuspendLayout();
        // 
        // panel1
        // 
        this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
        this->panel1->Location = System::Drawing::Point(160, 37);
        this->panel1->Name = L"panel1";
        this->panel1->Size = System::Drawing::Size(837, 447);
        this->panel1->TabIndex = 0;
        this->panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::panel1_Paint);
        this->panel1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseDown);
        this->panel1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseMove);
        this->panel1->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseUp);
        // 
        // colorBox1
        // 
        this->colorBox1->AutoSize = true;
        this->colorBox1->BackColor = System::Drawing::Color::White;
        this->colorBox1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
        this->colorBox1->Location = System::Drawing::Point(16, 148);
        this->colorBox1->MinimumSize = System::Drawing::Size(37, 37);
        this->colorBox1->Name = L"colorBox1";
        this->colorBox1->Size = System::Drawing::Size(37, 37);
        this->colorBox1->TabIndex = 6;
        this->colorBox1->BackColorChanged += gcnew System::EventHandler(this, &Form1::colorBox1_BackColorChanged);
        // 
        // BtnPix1
        // 
        this->BtnPix1->AutoSize = true;
        this->BtnPix1->Checked = true;
        this->BtnPix1->Location = System::Drawing::Point(83, 213);
        this->BtnPix1->Name = L"BtnPix1";
        this->BtnPix1->Size = System::Drawing::Size(56, 17);
        this->BtnPix1->TabIndex = 7;
        this->BtnPix1->TabStop = true;
        this->BtnPix1->Text = L"1 Pixel";
        this->BtnPix1->UseVisualStyleBackColor = true;
        this->BtnPix1->CheckedChanged += gcnew System::EventHandler(this, &Form1::BtnPix1_CheckedChanged);
        // 
        // BtnPix3
        // 
        this->BtnPix3->AutoSize = true;
        this->BtnPix3->Location = System::Drawing::Point(83, 236);
        this->BtnPix3->Name = L"BtnPix3";
        this->BtnPix3->Size = System::Drawing::Size(56, 17);
        this->BtnPix3->TabIndex = 8;
        this->BtnPix3->Text = L"3 Pixel";
        this->BtnPix3->UseVisualStyleBackColor = true;
        this->BtnPix3->CheckedChanged += gcnew System::EventHandler(this, &Form1::BtnPix3_CheckedChanged);
        // 
        // BtnPix5
        // 
        this->BtnPix5->AutoSize = true;
        this->BtnPix5->Location = System::Drawing::Point(83, 259);
        this->BtnPix5->Name = L"BtnPix5";
        this->BtnPix5->Size = System::Drawing::Size(56, 17);
        this->BtnPix5->TabIndex = 9;
        this->BtnPix5->Text = L"5 Pixel";
        this->BtnPix5->UseVisualStyleBackColor = true;
        this->BtnPix5->CheckedChanged += gcnew System::EventHandler(this, &Form1::BtnPix5_CheckedChanged);
        // 
        // toolStrip1
        // 
        this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(5) {this->toolStripBtnLine, 
            this->toolStripBtnSquare, this->toolStripBtnEllipse, this->toolStripBtnColor, this->toolStripBtnLineColor});
        this->toolStrip1->Location = System::Drawing::Point(0, 0);
        this->toolStrip1->Name = L"toolStrip1";
        this->toolStrip1->Size = System::Drawing::Size(1016, 25);
        this->toolStrip1->TabIndex = 10;
        this->toolStrip1->Text = L"toolStrip1";
        this->toolStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &Form1::toolStrip1_ItemClicked);
        // 
        // toolStripBtnLine
        // 
        this->toolStripBtnLine->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text;
        this->toolStripBtnLine->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripBtnLine.Image")));
        this->toolStripBtnLine->ImageTransparentColor = System::Drawing::Color::Magenta;
        this->toolStripBtnLine->Name = L"toolStripBtnLine";
        this->toolStripBtnLine->Size = System::Drawing::Size(33, 22);
        this->toolStripBtnLine->Text = L"Line";
        this->toolStripBtnLine->Click += gcnew System::EventHandler(this, &Form1::toolStripBtnLine_Click);
        // 
        // toolStripBtnSquare
        // 
        this->toolStripBtnSquare->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text;
        this->toolStripBtnSquare->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripBtnSquare.Image")));
        this->toolStripBtnSquare->ImageTransparentColor = System::Drawing::Color::Magenta;
        this->toolStripBtnSquare->Name = L"toolStripBtnSquare";
        this->toolStripBtnSquare->Size = System::Drawing::Size(47, 22);
        this->toolStripBtnSquare->Text = L"Square";
        this->toolStripBtnSquare->Click += gcnew System::EventHandler(this, &Form1::toolStripBtnSquare_Click);
        // 
        // toolStripBtnEllipse
        // 
        this->toolStripBtnEllipse->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text;
        this->toolStripBtnEllipse->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripBtnEllipse.Image")));
        this->toolStripBtnEllipse->ImageTransparentColor = System::Drawing::Color::Magenta;
        this->toolStripBtnEllipse->Name = L"toolStripBtnEllipse";
        this->toolStripBtnEllipse->Size = System::Drawing::Size(44, 22);
        this->toolStripBtnEllipse->Text = L"Ellipse";
        this->toolStripBtnEllipse->Click += gcnew System::EventHandler(this, &Form1::toolStripBtnEllipse_Click);
        // 
        // toolStripBtnColor
        // 
        this->toolStripBtnColor->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text;
        this->toolStripBtnColor->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripBtnColor.Image")));
        this->toolStripBtnColor->ImageTransparentColor = System::Drawing::Color::Magenta;
        this->toolStripBtnColor->Name = L"toolStripBtnColor";
        this->toolStripBtnColor->Size = System::Drawing::Size(58, 22);
        this->toolStripBtnColor->Text = L"Fill Color";
        this->toolStripBtnColor->Click += gcnew System::EventHandler(this, &Form1::toolStripBtnColor_Click);
        // 
        // toolStripBtnLineColor
        // 
        this->toolStripBtnLineColor->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Text;
        this->toolStripBtnLineColor->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"toolStripBtnLineColor.Image")));
        this->toolStripBtnLineColor->ImageTransparentColor = System::Drawing::Color::Magenta;
        this->toolStripBtnLineColor->Name = L"toolStripBtnLineColor";
        this->toolStripBtnLineColor->Size = System::Drawing::Size(65, 22);
        this->toolStripBtnLineColor->Text = L"Line Color";
        this->toolStripBtnLineColor->Click += gcnew System::EventHandler(this, &Form1::toolStripBtnLineColor_Click);
        // 
        // labelPos1
        // 
        this->labelPos1->AutoSize = true;
        this->labelPos1->Location = System::Drawing::Point(712, 504);
        this->labelPos1->Name = L"labelPos1";
        this->labelPos1->Size = System::Drawing::Size(35, 13);
        this->labelPos1->TabIndex = 11;
        this->labelPos1->Text = L"label1";
        // 
        // labelPos2
        // 
        this->labelPos2->AutoSize = true;
        this->labelPos2->Location = System::Drawing::Point(848, 504);
        this->labelPos2->Name = L"labelPos2";
        this->labelPos2->Size = System::Drawing::Size(35, 13);
        this->labelPos2->TabIndex = 12;
        this->labelPos2->Text = L"label2";
        // 
        // BtnPix7
        // 
        this->BtnPix7->AutoSize = true;
        this->BtnPix7->Location = System::Drawing::Point(83, 282);
        this->BtnPix7->Name = L"BtnPix7";
        this->BtnPix7->Size = System::Drawing::Size(56, 17);
        this->BtnPix7->TabIndex = 13;
        this->BtnPix7->Text = L"7 Pixel";
        this->BtnPix7->UseVisualStyleBackColor = true;
        this->BtnPix7->CheckedChanged += gcnew System::EventHandler(this, &Form1::BtnPix7_CheckedChanged);
        // 
        // BtnPix10
        // 
        this->BtnPix10->AutoSize = true;
        this->BtnPix10->Location = System::Drawing::Point(83, 306);
        this->BtnPix10->Name = L"BtnPix10";
        this->BtnPix10->Size = System::Drawing::Size(62, 17);
        this->BtnPix10->TabIndex = 14;
        this->BtnPix10->Text = L"10 Pixel";
        this->BtnPix10->UseVisualStyleBackColor = true;
        this->BtnPix10->CheckedChanged += gcnew System::EventHandler(this, &Form1::BtnPix10_CheckedChanged);
        // 
        // BtnPix15
        // 
        this->BtnPix15->AutoSize = true;
        this->BtnPix15->Location = System::Drawing::Point(83, 329);
        this->BtnPix15->Name = L"BtnPix15";
        this->BtnPix15->Size = System::Drawing::Size(62, 17);
        this->BtnPix15->TabIndex = 15;
        this->BtnPix15->Text = L"15 Pixel";
        this->BtnPix15->UseVisualStyleBackColor = true;
        this->BtnPix15->CheckedChanged += gcnew System::EventHandler(this, &Form1::BtnPix15_CheckedChanged);
        // 
        // panel2
        // 
        this->panel2->BackColor = System::Drawing::Color::White;
        this->panel2->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
        this->panel2->Location = System::Drawing::Point(83, 148);
        this->panel2->Name = L"panel2";
        this->panel2->Size = System::Drawing::Size(37, 37);
        this->panel2->TabIndex = 17;
        // 
        // colorBox2
        // 
        this->colorBox2->AutoSize = true;
        this->colorBox2->BackColor = System::Drawing::Color::Black;
        this->colorBox2->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
        this->colorBox2->Location = System::Drawing::Point(16, 213);
        this->colorBox2->MinimumSize = System::Drawing::Size(37, 37);
        this->colorBox2->Name = L"colorBox2";
        this->colorBox2->Size = System::Drawing::Size(37, 37);
        this->colorBox2->TabIndex = 18;
        this->colorBox2->BackColorChanged += gcnew System::EventHandler(this, &Form1::colorBox2_BackColorChanged);
        // 
        // label1
        // 
        this->label1->AutoSize = true;
        this->label1->Location = System::Drawing::Point(8, 250);
        this->label1->Name = L"label1";
        this->label1->Size = System::Drawing::Size(54, 13);
        this->label1->TabIndex = 19;
        this->label1->Text = L"Line Color";
        // 
        // label2
        // 
        this->label2->AutoSize = true;
        this->label2->Location = System::Drawing::Point(12, 185);
        this->label2->Name = L"label2";
        this->label2->Size = System::Drawing::Size(46, 13);
        this->label2->TabIndex = 20;
        this->label2->Text = L"Fill Color";
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->BackColor = System::Drawing::SystemColors::Control;
        this->ClientSize = System::Drawing::Size(1016, 538);
        this->Controls->Add(this->label2);
        this->Controls->Add(this->label1);
        this->Controls->Add(this->colorBox2);
        this->Controls->Add(this->panel2);
        this->Controls->Add(this->BtnPix15);
        this->Controls->Add(this->BtnPix10);
        this->Controls->Add(this->BtnPix7);
        this->Controls->Add(this->labelPos2);
        this->Controls->Add(this->labelPos1);
        this->Controls->Add(this->toolStrip1);
        this->Controls->Add(this->BtnPix5);
        this->Controls->Add(this->BtnPix3);
        this->Controls->Add(this->BtnPix1);
        this->Controls->Add(this->colorBox1);
        this->Controls->Add(this->panel1);
        this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
        this->MinimumSize = System::Drawing::Size(1024, 530);
        this->Name = L"Form1";
        this->Text = L"Lab 6 Paint";
        this->toolStrip1->ResumeLayout(false);
        this->toolStrip1->PerformLayout();
        this->ResumeLayout(false);
        this->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->AllowFullOpen = false;
  // Allows the user to get help. (The default is false.)
  MyDialog->ShowHelp = true;
  // Sets the initial color select to the current text color.
  MyDialog->Color = panel1->ForeColor;

  // Update the text box color if the user clicks OK  
  if ( MyDialog->ShowDialog() == ::System::Windows::Forms::DialogResult::OK )
         {
            colorBox1->BackColor= MyDialog->Color;
            sColor = Convert::ToString(colorBox1->BackColor);
        //  labelColor->Text=sColor;
         }
     }
     private: System::Void panel1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
        if( e->Button== System::Windows::Forms::MouseButtons::Left)
            {
             Drawing = true;
             firstPoint = e->Location;
             labelPos1->Text = Convert::ToString(e->Location);
             // set shape flag
            } 
        if( e->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) 
     {

// tempPos=e->位置;labelPos2->Text = Convert::ToString(e->Location);

         if(Drawing)
         {
             //draw temp outline with no fill and black outline
              panel1->Refresh();
             auto g = panel1->CreateGraphics();

             switch(iShape)
             {
             case 1:
                 g->DrawLine(Pens::Black,firstPoint,e->Location);
                 break;
             case 2:
                 g->DrawRectangle(Pens::Black,firstPoint.X,firstPoint.Y,(e->Location.X-firstPoint.X),(e->Location.Y-firstPoint.Y));
                 break;
             case 3:
                 g->DrawEllipse(Pens::Black,firstPoint.X,firstPoint.Y,(e->Location.X-firstPoint.X),(e->Location.Y-firstPoint.Y));
             default:break;

             }


         }
         if(move)
         {
             //code
             panel1->Refresh();
             auto g = panel1->CreateGraphics();
             firstPoint=e->Location;
             SolidBrush^ myBrush = gcnew SolidBrush(Color::FromArgb(colorBox1->BackColor.A,colorBox1->BackColor.R,colorBox1->BackColor.G,colorBox1->BackColor.B) );
             Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
             myPen->Width = iPix;

             switch(iShape)
             {
             case 1:
                 finalPoint.X=iSize.X+firstPoint.X;
                 finalPoint.Y=iSize.Y+firstPoint.Y;
                 g->DrawLine(myPen,firstPoint,finalPoint);
                 break;
             case 2:
                 g->FillRectangle(myBrush,firstPoint.X,firstPoint.Y,iSize.X,iSize.Y);
                 g->DrawRectangle(myPen,firstPoint.X,firstPoint.Y,iSize.X,iSize.Y);
                 break;
             case 3:
                 g->FillEllipse(myBrush,firstPoint.X,firstPoint.Y,iSize.X,iSize.Y);
                 g->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->Button== System::Windows::Forms::MouseButtons::Left)
            {
             finalPoint = e->Location;
             labelPos2->Text = Convert::ToString(e->Location);
             // draw filled shape

             panel1->Refresh();
             auto g = panel1->CreateGraphics();
             SolidBrush^ myBrush = gcnew SolidBrush(Color::FromArgb(colorBox1->BackColor.A,colorBox1->BackColor.R,colorBox1->BackColor.G,colorBox1->BackColor.B) );
             Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
             myPen->Width = iPix;

             switch(iShape)
             {
             case 1:
                 g->DrawLine(myPen,firstPoint,finalPoint);
                 break;
             case 2:
                 g->FillRectangle(myBrush,firstPoint.X,firstPoint.Y,(e->Location.X-firstPoint.X),(e->Location.Y-firstPoint.Y));
                 g->DrawRectangle(myPen,firstPoint.X,firstPoint.Y,(e->Location.X-firstPoint.X),(e->Location.Y-firstPoint.Y));
                 break;
             case 3:
                 g->FillEllipse(myBrush,firstPoint.X,firstPoint.Y,(e->Location.X-firstPoint.X),(e->Location.Y-firstPoint.Y));
                 g->DrawEllipse(myPen,firstPoint.X,firstPoint.Y,(e->Location.X-firstPoint.X),(e->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->Refresh();
         auto g = panel2->CreateGraphics();
         Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
         myPen->Width = iPix;
         g->DrawLine(myPen,2,18,33,18);
     }
           private: System::Void BtnPix3_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
         iPix=3;
         panel2->Refresh();
         auto g = panel2->CreateGraphics();
         Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
         myPen->Width = iPix;
         g->DrawLine(myPen,2,18,33,18);
     }
          private: System::Void BtnPix5_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
         iPix=5;
         panel2->Refresh();
         auto g = panel2->CreateGraphics();
         Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
         myPen->Width = iPix;
         g->DrawLine(myPen,2,18,33,18);
     }
         private: System::Void BtnPix7_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
         iPix=7;
         panel2->Refresh();
         auto g = panel2->CreateGraphics();
         Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
         myPen->Width = iPix;
         g->DrawLine(myPen,2,18,33,18);
     }
           private: System::Void BtnPix10_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
         iPix=10;
         panel2->Refresh();
         auto g = panel2->CreateGraphics();
         Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
         myPen->Width = iPix;
         g->DrawLine(myPen,2,18,33,18);
     }
            private: System::Void BtnPix15_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
         iPix=15;
         panel2->Refresh();
         auto g = panel2->CreateGraphics();
         Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
         myPen->Width = iPix;
         g->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->AllowFullOpen = false;
    // Allows the user to get help. (The default is false.)
    MyDialog->ShowHelp = true;
    // Sets the initial color select to the current text color.
    MyDialog->Color = colorBox2->BackColor;

  // Update the text box color if the user clicks OK  
  if ( MyDialog->ShowDialog() == ::System::Windows::Forms::DialogResult::OK )
         {
            sColorLine = Convert::ToString(MyDialog->Color);
        //  labelColorLine->Text=sColorLine;
            colorBox2->BackColor= MyDialog->Color;
         }
     }
           private: System::Void colorBox1_BackColorChanged(System::Object^  sender, System::EventArgs^  e) {
          panel1->Refresh();
             auto g = panel1->CreateGraphics();
             SolidBrush^ myBrush = gcnew SolidBrush(Color::FromArgb(colorBox1->BackColor.A,colorBox1->BackColor.R,colorBox1->BackColor.G,colorBox1->BackColor.B) );
             Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
             myPen->Width = iPix;

             switch(iShape)
             {
             case 1:
                 g->DrawLine(myPen,firstPoint,finalPoint);
                 break;
             case 2:
                 g->FillRectangle(myBrush,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y));
                 g->DrawRectangle(myPen,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y));
                 break;
             case 3:
                 g->FillEllipse(myBrush,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y));
                 g->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->Refresh();
             auto g = panel1->CreateGraphics();
             SolidBrush^ myBrush = gcnew SolidBrush(Color::FromArgb(colorBox1->BackColor.A,colorBox1->BackColor.R,colorBox1->BackColor.G,colorBox1->BackColor.B) );
             Pen^ myPen = gcnew Pen(Color::FromArgb(colorBox2->BackColor.A,colorBox2->BackColor.R,colorBox2->BackColor.G,colorBox2->BackColor.B) );
             myPen->Width = iPix;

             switch(iShape)
             {
             case 1:
                 g->DrawLine(myPen,firstPoint,finalPoint);
                 break;
             case 2:
                 g->FillRectangle(myBrush,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y));
                 g->DrawRectangle(myPen,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y));
                 break;
             case 3:
                 g->FillEllipse(myBrush,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y));
                 g->DrawEllipse(myPen,firstPoint.X,firstPoint.Y,(finalPoint.X-firstPoint.X),(finalPoint.Y-firstPoint.Y));
                 break;
             default:break;
            } 
     }

}; }

4

1 回答 1

7

如果您不专注于使用名为 的函数push_back,但Add可以使用 ,则可以使用 .NET 提供的集合来存储 .NET 数据。

using namespace System::Collections::Generic;

List<int> vShape;
List<Point> vfirstPoint;
List<Point> vSize;
List<float> vPix;
List<String^> vfillColor;
List<String^> vlineColor;

System::Collections::Generic::List<T>类似于std::vectorSystem::Collections::Generic::LinkedList<T>std::listSystem::Collections::Generic::Dictionary<TKey, TValue>std::unordered_map

于 2012-11-08T03:08:18.413 回答