#pragma once ///////////////////////////////////////////////////////////////////// // Form1.h - Demo of techniques to build C++ WinForm interface // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 2006 // ///////////////////////////////////////////////////////////////////// namespace manCppWinForm { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace System::IO; /// WARNING: /// If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); } protected: ~Form1() { if (components) { delete components; } } protected: private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::TextBox^ textBox1; private: System::Windows::Forms::FolderBrowserDialog^ folderBrowserDialog1; private: System::Windows::Forms::ListBox^ listBox1; private: System::Windows::Forms::Button^ button2; private: System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// void InitializeComponent(void) { this->button1 = (gcnew System::Windows::Forms::Button()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog()); this->listBox1 = (gcnew System::Windows::Forms::ListBox()); this->button2 = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // button1 // this->button1->Anchor = static_cast((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right)); this->button1->Location = System::Drawing::Point(531, 48); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(94, 23); this->button1->TabIndex = 0; this->button1->Text = L"Browse"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // textBox1 // this->textBox1->Anchor = static_cast(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left) | System::Windows::Forms::AnchorStyles::Right)); this->textBox1->Font = (gcnew System::Drawing::Font(L"Tahoma", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast(0))); this->textBox1->Location = System::Drawing::Point(51, 48); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(460, 23); this->textBox1->TabIndex = 1; // // listBox1 // this->listBox1->Anchor = static_cast((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) | System::Windows::Forms::AnchorStyles::Left) | System::Windows::Forms::AnchorStyles::Right)); this->listBox1->Font = (gcnew System::Drawing::Font(L"Tahoma", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast(0))); this->listBox1->FormattingEnabled = true; this->listBox1->ItemHeight = 16; this->listBox1->Location = System::Drawing::Point(51, 90); this->listBox1->Name = L"listBox1"; this->listBox1->Size = System::Drawing::Size(460, 276); this->listBox1->TabIndex = 2; // // button2 // this->button2->Anchor = static_cast((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right)); this->button2->Location = System::Drawing::Point(531, 90); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(94, 23); this->button2->TabIndex = 0; this->button2->Text = L"Get Files"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(661, 398); this->Controls->Add(this->listBox1); this->Controls->Add(this->textBox1); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->Name = L"Form1"; this->Text = L"Form1"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion // //----< Show folder browser and get user's selected path >--------- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { folderBrowserDialog1 = gcnew FolderBrowserDialog(); folderBrowserDialog1->ShowNewFolderButton = false; folderBrowserDialog1->SelectedPath = Directory::GetCurrentDirectory(); System::Windows::Forms::DialogResult result; result = folderBrowserDialog1->ShowDialog(); if(result == System::Windows::Forms::DialogResult::OK) { Directory::SetCurrentDirectory(folderBrowserDialog1->SelectedPath); textBox1->Text = Directory::GetCurrentDirectory(); listBox1->Items->Clear(); } } //----< Display all files in the current directory >--------------- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { listBox1->Items->Clear(); array^ files = Directory::GetFiles(Directory::GetCurrentDirectory()); int len = files->Length; for(int i=0; iLength; ++i) { String^ name = Path::GetFileName(files[i]); listBox1->Items->Add(name); } } //----< Initialize Form on startup >------------------------------- private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { this->Text = "C++ WinForm Demonstraton"; textBox1->Text = Directory::GetCurrentDirectory(); } }; }