I am struggling with how to make an Item selected from a ComboBox change the color of a square on the form. If I enter code in the OnClick event of the ComboBox, then as soon as I click the box the square changes color. But there are also Circle, Ellipse and rectangle in the drop down list of the ComboBox and clicking any one of them also changes the square red. I only want it to change if the Square is selected from the ComboBox. I am using Boreland C++ but with the extensions for Windows programming, rather like visual C++. You drop items onto a form and then get them to do things. Can anyone help with this, I've been stuck on it for ages.

you need to check to see which item has been selected

so when the event is raised do a check to make sure that the selected item is the right one.

you need to check to see which item has been selected

so when the event is raised do a check to make sure that the selected item is the right one.

I have the following code on the OnClick Event of the ComboBox. But clicking on any other item in the ComboBox, such as Rectangle or Circle also still changes the square red. Clicking on any item in the drop down box still activates this code. BUT I only want it ti be activated when SQUARE is selected from the DropDown List. If I select Circle, I dont want the Square to change in any way. Thanks for your input
Square->Brush->Color=clRed;

I have the following code on the OnClick Event of the ComboBox. But clicking on any other item in the ComboBox, such as Rectangle or Circle also still changes the square red. Clicking on any item in the drop down box still activates this code. BUT I only want it ti be activated when SQUARE is selected from the DropDown List. If I select Circle, I dont want the Square to change in any way. Thanks for your input
Square->Brush->Color=clRed;

Sorry forgot to include the code it was Square->Brush->Color = clRed

here is how it looks in dotnet

private: System::Void combobox_onClick(System::Object^ sender, System::EventArgs^ e) {
    if ( combobox->selecteditem == "Square" );
       {
          //do your coloring inside here
       }
}

also, since it is a combo box i would use the selectedindexchange event

which is only going to be thrown each time the index changes instead of each time the control is clicked

private: System::Void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
if ( comboBox1->SelectedItem == "FOO")
{
//do your magic here
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.