wtorek, 26 września 2017

Dynamically created control (class listBox) with its own function looking for files in the directory (Visual C++)

File Test_Cl.h :


using namespace System::IO;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

ref class files_ListBox : public System::Windows::Forms::ListBox
{
public: System::Void find_Files(System::String^ directory,System::String^ files)
{
System::Int64 i;

DirectoryInfo^ my_directory=gcnew DirectoryInfo(directory);
array<FileInfo^>^ my_files=my_directory->GetFiles(files);
for(i=0;i<my_files->Length;i++)
{
this->Items->Add(my_files[i]->Name+" "+my_files[i]->Length+" "+my_files[i]->CreationTime);
}

}

};

And a fragment of the file - Form1.h : 

#pragma once

#include "test_Cl.h"

private:
/// <summary>
/// Required designer variable.
/// </summary>
files_ListBox test_FLB;
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)
{
this->test_FLB=(gcnew files_ListBox());
this->SuspendLayout();
this->test_FLB->Name=L"test_FLB";
this->test_FLB->Location=System::Drawing::Point(Form1::Width/2,Form1::Height/2);
this->test_FLB->Size=System::Drawing::Size(200,200);



#pragma endregion
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
test_FLB->find_Files("c:\\Windows","*.txt*");
}
};
}


Brak komentarzy:

Prześlij komentarz