Useful function to setup combo boxes

The Function //************************************* //************************************* //********** SETUP COMBO BOX ********** //************************************* //************************************* private: void SetupComboBox (System::Windows::Forms::ComboBox ^TargetComboBox, int DefaultItem, array ^Items) { try { TargetComboBox->BeginUpdate(); TargetComboBox->SelectedIndex = -1; TargetComboBox->Items->Clear(); //Remove any existing items for each (String ^ItemString in Items) TargetComboBox->Items->Add(ItemString); TargetComboBox->SelectedIndex = DefaultItem; //Select default item } catch (Exception ^) { } finally { TargetComboBox->EndUpdate(); } […]

Read More

Arrays of Strings

Creating String Arrays Different ways to create string arrays: array<String^> ^myArray = gcnew array<string^>(10); //or array<String^> ^myArray; myArray = gcnew array<String^>(10); //or array<String^> ^myArray = {"channel8" "channel9", "technet" , "channel10", "msdn"}; Calling a function with an array of constant strings MyFunction((gcnew array {"Monday", "Tuesday", "Wednesday"}); Getting each entry from a list of strings array ^ports; […]

Read More

.Using Combo Boxes

Only permitting items in the list (YOU HAVE TO REMEMBER TO DO THIS TO BLOCK USER ENTERING THEIR OWN VALUES) DropDownStyle = DropDownList (Only accepts strings that are part of the selection list) Loading the contents of a comboBox at application startup cmbMyComboBox->BeginUpdate(); cmbMyComboBox->SelectedIndex = -1; cmbMyComboBox->Items->Clear(); //Remove Existing Items If Necessary for (Count = […]

Read More

Thread Safe Calls

If your application is doing asynchronous things, for instance a form has a callback function from a class receiving say some communications, then you will need to deal with calls to it in a thread safe way. The reason is that forms run on a single thread, but events in the other class will not […]

Read More

Using Message Boxes

Typical Info Message Box MessageBox::Show(L"Message Text", L"Message Box Title", MessageBoxButtons::OK, MessageBoxIcon::Information); Typical Error Message Box //1st string is message, 2nd string is box title. Here's a classic error message usage: catch (Exception^ e) { MessageBox::Show(L"Comms Failed with the following error:\n" + e, L"Error", MessageBoxButtons::OK, MessageBoxIcon::Error); } Exclamation Error Box MessageBox::Show(L"You can't do this", L"Not Possible", […]

Read More

Creating Simple Callback Function

Here’s step by step instructions of how to create a callback function which allows a function in one class to be called by some other class it is using (for instance, you may have a class you’ve created that provides communication functions and you want to pass received data back to the main class or […]

Read More

Converting IP Addresses

IP Address Text Entry Box You can use a MaskedTextBox with the mask "###.###.###.###" However its often best just to use a standard text box as the masked text box approah creates issues. Note that the Windows network setup IP address box is not based on a standard tool unfortunately. Parsing Removing Leading Zero's IPAddress::TryParse […]

Read More

Using Radio Buttons

Grouping Radio buttons must be grouped on a form, for instance inside a group box or Panel Usage MyRadioButton->Checked = true; MyRadioButton->Checked = false; if(!MyRadioButton->Checked) //If not checked Index Value There is no such thing any more in VC++

Read More

Add Image To A Form

A good format to save images in is .png Create images as 96dpi .png for optimum quality. Save the image file to your project directory Simply place a PictureBox control on the form where you want it, set the size and set the image filename as the picture to use. There is no need to […]

Read More