4

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.

Liban
  • 641
  • 5
  • 19
  • 32

2 Answers2

17

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 :

https://i.stack.imgur.com/8F35Y.png

Pierre-Luc Pineault
  • 8,993
  • 6
  • 40
  • 55
1

Yep, you can use an imagebox then when the configuration is succeed you make it visible and set it's image property to your green tick icon, and on the other hand if your config is failed you make it visible and change the image property to red Cross icon, if you need some more help let me know ;)

hm1984ir
  • 554
  • 3
  • 7