Click here to Skip to main content
16,022,060 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Using c# in Visual Studio 2022, I have two labels displaying output. I want the highest of the two outputs to be displayed in red forecolor. How do I code this?

What I have tried:

I don't know if I code it under calculation event handler or under label control. Also, do I code using min/ max or if/ else?
Posted
Comments
Dave Kreskowiak 21-Sep-24 20:11pm    
Without knowing the application type, it's impossible to tell you. Is this WinForms, WPF, ASP.NET, ... ?

1 solution

First off, ignore the label content: keep the values as numeric (float, double, integer, ...) variables and compare those instead of the text that a label contains. When new output values arrive, update the variables, and then the Label. At that point you can set the foreground colour of both labels to reflect the "highness" - I'd use a ternary conditional operator[^] rather than a min/max or an if...else
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900