Changing Button.BackColor in a Row Rule

I have a Classic UX customization utilizing an EpiButton, 2 row rules and a UD field. My row rules state that if UD field is true, I want the button’s backcolor to be red and text to be “Remove Urgent Material”. The 2nd row rules states that if UD field is false, I want the button’s backcolor to be silver and text to be “Set Urgent Material”.

The text is changing like a charm. However, the color is not changing. Yes, I have UseOSThemes set to false and UseAppStyling = false on the button properties.

What am I missing?

	private void SetButtonProperties(EpiButton button, System.Drawing.Color color, string caption)
	{
		button.UseAppStyling = false;
		button.BackColor = color;
		button.Text = caption;
	}

	private void CreateRowRuleJobMtlHotMtl_cEquals_true()
	{
		// Description: BtnHotMtlChangeColor
		// **** begin autogenerated code ****
		RuleAction[] ruleActions = new RuleAction[0];
		// Create RowRule and add to the EpiDataView.
		// Dummy Context Object
		object contextObject = null;
		RowRule rrCreateRowRuleJobMtlHotMtl_cEquals_true = new RowRule("JobMtl.HotMtl_c", RuleCondition.Equals, true, new RowRuleActionDelegate2(this.JobMtlHotMtl_cEqualstrue_CustomRuleAction), contextObject);
		((EpiDataView)(this.oTrans.EpiDataViews["JobMtl"])).AddRowRule(rrCreateRowRuleJobMtlHotMtl_cEquals_true);
		// **** end autogenerated code ****
	}

	private void JobMtlHotMtl_cEqualstrue_CustomRuleAction(Ice.Lib.ExtendedProps.RowRuleDelegateArgs args)
	{
		// ** RowRuleDelegateArgs Properties: args.Arg1, args.Arg2, args.Context, args.Row
		// ** put custom Rule Action logic here
		//btnHotMtl.Text = "Remove Urgent Material";
		//btnHotMtl.BackColor = System.Drawing.Color.Red;
		SetButtonProperties(btnHotMtl, System.Drawing.Color.Red, "Remove Urgent Material");
		
	}

	private void CreateRowRuleJobMtlHotMtl_cEquals_false()
	{
		// Description: BtnHotMtlUnsetColor
		// **** begin autogenerated code ****
		RuleAction[] ruleActions = new RuleAction[0];
		// Create RowRule and add to the EpiDataView.
		// Dummy Context Object
		object contextObject = null;
		RowRule rrCreateRowRuleJobMtlHotMtl_cEquals_false = new RowRule("JobMtl.HotMtl_c", RuleCondition.Equals, false, new RowRuleActionDelegate2(this.JobMtlHotMtl_cEqualsfalse_CustomRuleAction), contextObject);
		((EpiDataView)(this.oTrans.EpiDataViews["JobMtl"])).AddRowRule(rrCreateRowRuleJobMtlHotMtl_cEquals_false);
		// **** end autogenerated code ****
	}

	private void JobMtlHotMtl_cEqualsfalse_CustomRuleAction(Ice.Lib.ExtendedProps.RowRuleDelegateArgs args)
	{
		// ** RowRuleDelegateArgs Properties: args.Arg1, args.Arg2, args.Context, args.Row
		// ** put custom Rule Action logic here
		//btnHotMtl.Text = "Set Urgent Material";
		//btnHotMtl.BackColor = System.Drawing.Color.Green;
		SetButtonProperties(btnHotMtl, System.Drawing.Color.Green, "Set Urgent Material");
	}

Try adding this to your SetButtonProperties

button.UseVisualStyleBackColor = false;

Could try

button.Appearance.BackColor = color

as well.

For good measure throw

button.UseOsThemes = false;

in your SetButton method too

The UseVisualStyleBackColor threw an error but just changing the button.BackColor = color to button.Appearance.BackColor = color is the winner, winner, chicken dinner.!!!

private void SetButtonProperties(EpiButton button, System.Drawing.Color color, string caption)
{
	button.UseAppStyling = false;
	//button.UseVisualStyleBackColor = false;
	//button.BackColor = color;
	button.Appearance.BackColor = color;
	button.Text = caption;
}

Dammit! Julie. I thought I trained you better than @Ross.Fireball.Kuiper :stuck_out_tongue:

You want to give your button a binding JobMtl.btnHot for example, buttons and shapes can have fake bindings for the Row Rule Engine to work with them.

Now you can add a regular action, and have it run on JobMtl.btnHot, you will just need to modify the wizard generated code because you will not see the btnHot as a field in Wizard Script Editor.

Just assign it the OK Color or something else, once the code is generated replace the color with your custom ControlSettings.


But also consider Epicor native behaviour, perhaps a colored button isn’t the way, perhaps you want a Shape? Perhaps a Shape and a Checkbox next to it that can be toggled and the shape can become Red or Gray.

Further Reading:


Funny, I was just doing a Custom Color yesterday, because @jgiese.wci loves LimeGreen and hates Epicors default Green :slight_smile:


Bonus

Maestro @josecgomez has a Video on it in his gentle cuban voice.

It’s not lime green it’s the Excel colors!
image

But also yes their default color schemes and color choices are often… questionable at best lol

Whatever customization you made lime green use Pixie (Pixie / Nattyware) color picker and fix it :joy::rofl:

2 Likes

For sure, your colors on the Dispatch Dashboards are like eye-candy to look at, even someone color blind would appreciate them :slight_smile: I agree those are good choices.

I use pixie all the time, its bound to my PATH all I need to type is pixie in terminal.

1 Like

I appreciate all your input. I did consider the other options on my way to this point.

Josh is still the winner with the solution. He gets the chicken dinner.

Thanks for the input.

I was trying to save you a CustomAction and just let Epicor handle it, plus if you bind it the button will be disabled if no record is selected. :slight_smile: