is there a way that i can put a green tick or a red cross besides a label in windows forms? basically i need to show if configuration success or not. I am using c#.
Thanks.
Pretty easy to do.
You can add both images, or even labels as I'm using in this example, beside your text label and then toggle manually the Visible
property.
In this example, I'm using a button click to show the tick/cross :
private void button1_Click(object sender, EventArgs e)
{
lblCheck.Visible = false;
lblCross.Visible = false;
if (CheckConfiguration())
{
lblCheck.Visible = true;
}
else
{
lblCross.Visible = true;
}
}
In my designer, lblCheck
is a label containing the Unicode Character ✓ (\u2713) with color set as Green, and lblCross
a label containing X with color set as red, exactly at the same spot.
Or, you can go with only one label and change the Text & ForeColor property dynamically, like this :
lblVerif.Text = string.Empty;
if (CheckConfiguration())
{
lblVerif.Text = "✓";
lblVerif.ForeColor = Color.Green;
}
else
{
lblVerif.Text = "X";
lblVerif.ForeColor = Color.Red;
}
For both ways, it looks like this :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With