如何在winforms中放置绿色蜱或红十字? [英] How to put green tick or red cross in winforms?

查看:138
本文介绍了如何在winforms中放置绿色蜱或红十字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法可以在窗体中添加绿色标记或红色十字标记?基本上我需要显示配置是否成功。我正在使用c#。

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#.

谢谢。

推荐答案

很容易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;
        }
    }

在我的设计师中, lblCheck 是包含Unicode字符✓(\ u2713)且颜色设置为绿色的标签, lblCross 包含X且颜色设置为红色的标签,恰好在同一地点。

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.

或者,您只能使用一个标签并更改Text& ForeColor属性动态,如下所示:

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 :

这篇关于如何在winforms中放置绿色蜱或红十字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆