Working With Directories

using namespace System::IO; Does directory exist? (Note paths can include a filename if you wish) if (!Directory::Exists(Path::GetDirectoryName(MyFileName))) //or String ^path; path = "C:\\Atest\\"; // '\\'='\' if (!Directory::Exists(path)) //or if (!Directory::Exists("C:\\Atest\\")) // '\\'='\' Create Directory (Note paths can include a filename if you wish) Directory::CreateDirectory(Path::GetDirectoryName(MyFileName)); //or String ^path; path = "C:\\Atest\\"; // '\\'='\' Directory::CreateDirectory(path); //or Directory::CreateDirectory("C:\\Atest\\"); […]

Read More

Using Checked List Box

General Setup To cause the items in the CheckedListBox to be checked when you click them the first time, set the control’s CheckOnClick property to True. Clear All Items clbMyCheckedList->Items->Clear(); Clear Individual Items clbMyCheckedList->Items->RemoveAt(0); //Specify index position Add New Items clbMyCheckedList->BeginUpdate(); //Stop painting of the ListBox as items are added clbMyCheckedList->Items->Add(“Entry 1”, true); clbMyCheckedList->EndUpdate(); How […]

Read More

Convert Bytes To A String

array<Byte> ^RxData = gcnew array<Byte>(2); RxData[0] = 'A'; RxData[0] = 'B'; String ^sTemp; sTemp = System::Text::Encoding::UTF8->GetString(RxData); N.B. Make the array the length of the string – do not use a 0x00 terminating byte. If you do you get a resulting string but you can't add any new characters to it (e.g. MyString += "abc") because […]

Read More

Convert String To Byte Array

String Direct To Byte Array String ^sTemp; array<Byte> ^TxData; sTemp = “Hello”; TxData = System::Text::Encoding::UTF8->GetBytes(sTemp); Lengthy Method String ^Filename; Filename = “HELLO.TXT”; array<Char> ^NameArray = Filename->ToCharArray(); Array::Resize(NameArray, 13); //If you need to ensure a minimum size use this TxData[ByteId++] = Convert::ToByte(NameArray[0]); TxData[ByteId++] = Convert::ToByte(NameArray[1]); TxData[ByteId++] = Convert::ToByte(NameArray[2]); TxData[ByteId++] = Convert::ToByte(NameArray[3]); TxData[ByteId++] = Convert::ToByte(NameArray[4]); TxData[ByteId++] = […]

Read More

Using ListBox

List Box With More Options Need columns, colouring, icons etc? Use a List View Creating a List Box SelectionMode – Decide how many lines may be selected at a time by the user MultiColumn – Not what you think! A multicolumn ListBox places items into as many columns as are needed to make vertical scrolling […]

Read More

Using Tab Control

Event Triggered When A New Tab Is Selected if (tabControl1->SelectedIndex == 4) //SelectedIndex is the tab ID { } Disable A Page Of The Tab Control The page can still be selected and viewed, but all controls on it are disabled. MyTabControl->TabPages[1]->Enabled = false;  

Read More

.General Form Usage

Opening a form #include "FormName.h" //Add this at top of file frmConfiguration ^ConfigForm = gcnew frmConfiguration(); ConfigForm->PassedValue1 = "This is a string I'm passing"; //TO OPEN AS A DIALOG FORM: ConfigForm->ShowDialog(); //or if (ConfigForm->ShowDialog() == System::Windows::Forms::DialogResult::OK) else if (ConfigForm->DialogResult == System::Windows::Forms::DialogResult::Cancel) //TO OPEN NOT AS A DIALOG FORM: ConfigForm->Show(); Closing a form Close(); //or this->Close(); […]

Read More

Focus

Detecting Form Has Got Focus Use the ‘Activated’ event Bring Form To Front this->BringToFront(); Does A Specific Control Have Focus? if (txtMyTextBox->ContainsFocus) Give an object on the form focus //Use the objects focus property: ObjectName->Focus(); //or give the form itself focus: frmMyForm->Focus(); Forcing a form to always be on top Set the forms ‘Top Most’ […]

Read More

Determining Sender Type

Example Of How To Determine The Type Of System::Object private: void MyHandleEventFunction(System::Object^ sender, System::EventArgs^ e) { //WHAT TYPE OF OBJECT TRIGGERED THIS? if (sender->GetType() == System::Windows::Forms::ComboBox::typeid) { //OBJECT IS A COMBO BOX System::Windows::Forms::ComboBox ^TargetComboBox = (cli::safe_cast<system::windows::forms::combobox^>(sender)); = TargetComboBox->SelectedIndex;

Read More

Using safe_cast to access the object that triggered an event

An example using a single event triggered by multiple combo boxes //Setting up combo boxes MyComboBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &frmMain::GeneralComboBox_SelectedIndexChanged); MyComboBox1->Tag = 1; //In this example we use the tag property to store an ID we will use later MyComboBox2->SelectedIndexChanged += gcnew System::EventHandler(this, &frmMain::GeneralComboBox_SelectedIndexChanged); MyComboBox2->Tag = 2; MyComboBox3->SelectedIndexChanged += gcnew System::EventHandler(this, &frmMain::GeneralComboBox_SelectedIndexChanged); MyComboBox3->Tag = 3; […]

Read More