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(); } […]
All posts by
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; […]
.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 = […]
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 […]
Unions
Nope, you can’t use them in managed C++ as they are not safe.
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 […]
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 […]
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++
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 […]
