单击单选按钮时如何更改标签的前景色? [英] How do I change the forecolor of a label when I click on a radio button?

查看:135
本文介绍了单击单选按钮时如何更改标签的前景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击单选按钮时更改标签的字体颜色。我在Visual Studio 2015中使用Web表单。



我尝试过:



我试过label1.forecolor =Black,label1.forecolor = 00,00,00。和其他各种组合。

I want to change the font color of a label when I click on a radio button. I am using web form in Visual Studio 2015.

What I have tried:

I have tried label1.forecolor = "Black", label1.forecolor = 00,00,00. and various other combinations.

推荐答案

参考这个



refer this

<asp:RadioButtonList ID="rbcolor" AutoPostBack="true" runat="server" OnSelectedIndexChanged="rbcolor_SelectedIndexChanged"  >
           <asp:ListItem Text="Red" />
           <asp:ListItem Text="Green" />
           <asp:ListItem Text="Blue" />
       </asp:RadioButtonList>
       <asp:Label Text="My Label" ID="lblColor" runat="server" />




Protected Sub rbcolor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rbcolor.SelectedIndexChanged
       If (rbcolor.SelectedValue = "Red") Then
           lblColor.ForeColor = System.Drawing.Color.Red
       ElseIf (rbcolor.SelectedValue = "Green") Then
           lblColor.ForeColor = System.Drawing.Color.Green
       ElseIf (rbcolor.SelectedValue = "Blue") Then
           lblColor.ForeColor = System.Drawing.Color.Blue
       End If

   End Sub


这篇关于单击单选按钮时如何更改标签的前景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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