Form1.h

См. документацию.
00001 #pragma once
00002 #include "iostream"
00003 #include "list"
00004 
00005 namespace delme {
00006 
00007         using namespace System;
00008         using namespace System::ComponentModel;
00009         using namespace System::Collections;
00010         using namespace System::Windows::Forms;
00011         using namespace System::Data;
00012         using namespace System::Drawing;
00013         
00014 
00016         using namespace std;
00017 
00018 
00025 struct  MyStruct
00026 {
00027      char    onebyte;
00028      short   word;
00029      int     doubleword;
00030          int     i;
00031 }obj;
00032 
00033 
00038 list<MyStruct> thelist;
00039 
00040 
00050         public ref class Form1 : public System::Windows::Forms::Form
00051         {
00052 
00053         public:
00054                 Form1(void)
00055                 {
00056                         InitializeComponent();
00057                         //
00058                         //TODO: добавьте код конструктора
00059                         //
00060                 }
00061 
00062         protected:
00066                 ~Form1()
00067                 {
00068                         if (components)
00069                         {
00070                                 delete components;
00071                         }
00072                 }
00073         private: System::Windows::Forms::Button^  button1;
00074         protected: 
00075         private: System::Windows::Forms::ListBox^  listBox1;
00076         private: System::Windows::Forms::Label^  label1;
00077         private: System::Windows::Forms::ComboBox^  comboBox1;
00078         private: System::Windows::Forms::Label^  label2;
00079         private: System::Windows::Forms::TextBox^  textBox1;
00080         private: System::Windows::Forms::Label^  label3;
00081         private: System::Windows::Forms::ComboBox^  comboBox2;
00082 
00083 
00084 
00085         private:
00089                 System::ComponentModel::Container ^components;
00090 
00091 #pragma region Windows Form Designer generated code
00092 
00093 
00094 
00095 
00096                 void InitializeComponent(void)
00097                 {
00098                         this->button1 = (gcnew System::Windows::Forms::Button());
00099                         this->listBox1 = (gcnew System::Windows::Forms::ListBox());
00100                         this->label1 = (gcnew System::Windows::Forms::Label());
00101                         this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
00102                         this->label2 = (gcnew System::Windows::Forms::Label());
00103                         this->textBox1 = (gcnew System::Windows::Forms::TextBox());
00104                         this->label3 = (gcnew System::Windows::Forms::Label());
00105                         this->comboBox2 = (gcnew System::Windows::Forms::ComboBox());
00106                         this->SuspendLayout();
00107                         // 
00108                         // button1
00109                         // 
00110                         this->button1->Location = System::Drawing::Point(205, 238);
00111                         this->button1->Name = L"button1";
00112                         this->button1->Size = System::Drawing::Size(75, 23);
00113                         this->button1->TabIndex = 0;
00114                         this->button1->Text = L"добавить";
00115                         this->button1->UseVisualStyleBackColor = true;
00116                         this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
00117                         // 
00118                         // listBox1
00119                         // 
00120                         this->listBox1->FormattingEnabled = true;
00121                         this->listBox1->Location = System::Drawing::Point(12, 12);
00122                         this->listBox1->Name = L"listBox1";
00123                         this->listBox1->Size = System::Drawing::Size(268, 121);
00124                         this->listBox1->TabIndex = 1;
00125                         // 
00126                         // label1
00127                         // 
00128                         this->label1->AutoSize = true;
00129                         this->label1->Location = System::Drawing::Point(9, 155);
00130                         this->label1->Name = L"label1";
00131                         this->label1->Size = System::Drawing::Size(76, 13);
00132                         this->label1->TabIndex = 2;
00133                         this->label1->Text = L"выберите тип";
00134                         // 
00135                         // comboBox1
00136                         // 
00137                         this->comboBox1->FormattingEnabled = true;
00138                         this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"char(1 byte)", L"short(2 byte)", L"int(4 byte)"});
00139                         this->comboBox1->Location = System::Drawing::Point(12, 184);
00140                         this->comboBox1->Name = L"comboBox1";
00141                         this->comboBox1->Size = System::Drawing::Size(121, 21);
00142                         this->comboBox1->TabIndex = 3;
00143                         // 
00144                         // label2
00145                         // 
00146                         this->label2->AutoSize = true;
00147                         this->label2->Location = System::Drawing::Point(12, 217);
00148                         this->label2->Name = L"label2";
00149                         this->label2->Size = System::Drawing::Size(106, 13);
00150                         this->label2->TabIndex = 4;
00151                         this->label2->Text = L"напишите значение";
00152                         // 
00153                         // textBox1
00154                         // 
00155                         this->textBox1->Location = System::Drawing::Point(12, 241);
00156                         this->textBox1->Name = L"textBox1";
00157                         this->textBox1->Size = System::Drawing::Size(121, 20);
00158                         this->textBox1->TabIndex = 5;
00159                         // 
00160                         // label3
00161                         // 
00162                         this->label3->AutoSize = true;
00163                         this->label3->Location = System::Drawing::Point(139, 155);
00164                         this->label3->Name = L"label3";
00165                         this->label3->Size = System::Drawing::Size(149, 13);
00166                         this->label3->TabIndex = 6;
00167                         this->label3->Text = L"вставить перед элементом:";
00168                         // 
00169                         // comboBox2
00170                         // 
00171                         this->comboBox2->FormattingEnabled = true;
00172                         this->comboBox2->Location = System::Drawing::Point(164, 184);
00173                         this->comboBox2->Name = L"comboBox2";
00174                         this->comboBox2->Size = System::Drawing::Size(121, 21);
00175                         this->comboBox2->TabIndex = 7;
00176                         // 
00177                         // Form1
00178                         // 
00179                         this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
00180                         this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
00181                         this->ClientSize = System::Drawing::Size(292, 273);
00182                         this->Controls->Add(this->comboBox2);
00183                         this->Controls->Add(this->label3);
00184                         this->Controls->Add(this->textBox1);
00185                         this->Controls->Add(this->label2);
00186                         this->Controls->Add(this->comboBox1);
00187                         this->Controls->Add(this->label1);
00188                         this->Controls->Add(this->listBox1);
00189                         this->Controls->Add(this->button1);
00190                         this->Name = L"Form1";
00191                         this->Text = L"Form1";
00192                         this->ResumeLayout(false);
00193                         this->PerformLayout();
00194 
00195                 }
00196 #pragma endregion
00197 
00198 
00202                 void elemshow(){
00203                   list<MyStruct>::iterator i;
00204               int j=0;
00205               int elem;
00206                listBox1->Items->Clear();
00207                comboBox2->Items->Clear();
00208 
00209                for (i=thelist.begin();i!=thelist.end();++i){
00210                 j++;
00211                 comboBox2->Items->Add(j.ToString());
00212             MyStruct u=*i;
00213                         if (u.i==1) {elem=u.onebyte;listBox1->Items->Add("элемент № "+j+" : "+elem.ToString()+" ; тип : байт" );}
00214                         if (u.i==2) {elem=u.word;listBox1->Items->Add("элемент № "+j+" : "+elem.ToString()+" ; тип : слово" );}
00215                         if (u.i==3) {elem=u.doubleword;listBox1->Items->Add("элемент № "+j+" : "+elem.ToString()+" ; тип : двойное слово" );}
00216                         
00217               }
00218                 }
00219 
00220 
00224                 void CleanObj(){                
00225                                  obj.i=0; 
00226                                  obj.onebyte=0;
00227                  obj.word=0;
00228                  obj.doubleword=0;      
00229                 }
00230 
00231 
00232 
00241         void WriteObj(){
00242           if (comboBox1->SelectedIndex==0){
00243                 obj.i=1;
00244                 obj.onebyte=Convert::ToInt16(textBox1->Text);
00245          }
00246           if (comboBox1->SelectedIndex==1) {
00247                 obj.i=2;
00248                 obj.word=Convert::ToInt16(textBox1->Text);;
00249          }
00250           if (comboBox1->SelectedIndex==2){              
00251             obj.i=3;
00252                 obj.doubleword=Convert::ToInt32(textBox1->Text);;
00253          }
00254         if (comboBox2->Text==""){
00255                 thelist.push_back(obj);
00256         }
00257         else{
00258         list<MyStruct>::iterator k;
00259                 int h=0;
00260          for (k=thelist.begin();k!=thelist.end();++k){
00261           MyStruct u=*k;
00262           h++;
00263                   if (h== Convert::ToInt32(comboBox2->Text)){
00264            thelist.insert(k,obj);
00265            break;
00266           }
00267          }      
00268             }
00269         }
00270 
00271 
00272 
00276         private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
00277          try{
00278         CleanObj();// очищаем элемент списка 
00279         WriteObj();// записываем
00280         elemshow();// вывод элементов списка в listbox
00281          }
00282          catch (System::Exception ^ex){
00283                  MessageBox::Show(ex->Message, "Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error);
00284          }
00285                          }
00286                          
00287         };
00288 }
00289