Setting Event Handlers in Configurators and Setting Background Colors for Controls

Hey All,
I’ve been finding a lot of information out there on how to get more robust configurator user interfaces. One thing that I have found very useful is setting event handlers. If you look at the class documentation for the Control class, there are many existing events that you can configure. I have used this functionality to change background colors of controls to indicate invalid entries. Here is the code to set the event handler:

Inputs.HangonSpeedrail2_cmb.Control.LostFocus += (s, e) =>
{
    HangonSpeedRail2_LostFocus (false);
};

Here is the code to change the background colors of an UltraComboBox back and forth from red to default:

if (Inputs.Model_cmb.Control.Appearance.BackColor == Color.Red)
{
    Inputs.Model_cmb.Control.Appearance.BackColor = Color.White;
    Inputs.Model_cmb.Control.UseAppStyling = true;
}
else
{
    Inputs.Model_cmb.Control.Appearance.BackColor = Color.Red;
    Inputs.Model_cmb.Control.UseAppStyling = false;
}

Here is the code to change the background colors of a Decimal or TextBox:

if (Inputs.Model_dec.Control.BackColor == Color.Red)
{
    Inputs.Model_dec.Control.BackColor = Color.White;
    Inputs.Model_dec.Control.UseAppStyling = true;
}
else
{
    Inputs.Model_dec.Control.BackColor = Color.Red;
    Inputs.Model_dec.Control.UseAppStyling = false;
}

Enjoy!
Matthew

2 Likes

How would you use the “lost focus” event?
I have used the contains focus for controlling when some things do/dont run… Are you saying that you can trigger something to happen just when someone passes through a field without changing it?

That is correct. Our product offering has a lot of accessories, most with a location and often zero is not a valid input for our purposes. However, the value has not changed from the default zero value so an onChanged expression wouldn’t help much.

So, it’s usually a combo box(to select the option) with a decimal box directly next to it to enter the location value. When the option is selected on the combo box, focus is immediately transferred to the location decimal box( using Inputs.DecimalBox.Control.Focus() in the onChanged Expression ). This forces the user to leave the location field, triggering the LostFocus event containing my validation code. This way I can tell the user immediately that zero is not valid and then set the background of the field to red, and reset it when they give valid input.