如何制作标签选择2个或更多文本选项之一? [英] How do I make a label choose one of 2 or more text options?

查看:57
本文介绍了如何制作标签选择2个或更多文本选项之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这个可行,但是当我执行它时,它表示它有错误,紫色无法转换为"长" 

I want this to work but when I execute it, it says it has an error, that violet can't be conversed to "long" 

推荐答案

 那么决定标签是否应显示的条件是什么?紫光和QUOT;或"橙色"? 需要有一些条件决定选择其中一个。 例如...

 So what condition is it that will decide if the label should display "Violet" or "Orange"?  There needs to be some condition that will decide to choose one or the other.  For example...

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        'If the checkbox is checked, then the label displays "Violet" (Else) it displays "Orange"
        If CheckBox1.Checked Then 'the checkbox being checked is the condition that decides what to display
            Label1.Text = "Violet"
        Else
            Label1.Text = "Orange"
        End If

    End Sub


 

 

 您在Form的Load事件中执行此操作,该事件仅在表单加载时引发一次, 也许你想让它随机选择一个或另一个。 在那种情况下, 使用Random类随机选择一个或另一个。

 Being you are doing this in the Form's Load event which is only raised once when the form loads,  maybe you want to have it randomly choose one or the other.  In that case,  use the Random class to select one or the other randomly.

Public Class Form1
    Private Rand As New Random

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim RandomNumber As Integer = Rand.Next(101) 'gets a random number between 0 and 100
        If RandomNumber >= 50 Then 'if the random number is 50 or greater then display "Violet" (Else) display "Orange"
            Label1.Text = "Violet"
        Else
            Label1.Text = "Orange"
        End If
    End Sub
End Class


这篇关于如何制作标签选择2个或更多文本选项之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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