求救!!关于C#,如何改变文本框字体??悬赏10分!
这是我们老师留的作业,要求“利用RadioButton、RadioButtonList、CheckBox和CheckBoxList等控件动态地改变字体显示效果”。我想使用...
这是我们老师留的作业,要求“利用RadioButton、RadioButtonList、CheckBox和CheckBoxList等控件动态地改变字体显示效果”。我想使用RadioButtonlist获取选择的字体后赋值给textbox,但是编译无法通过。
以下是我的代码:
aspx:
<body>
<form id="form1" runat="server">
<div>
</div>
请输入您希望的文字:
<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem>宋体</asp:ListItem>
<asp:ListItem>隶书</asp:ListItem>
<asp:ListItem>黑体</asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButton ID="RadioButton1" runat="server" Text="宋体" GroupName="aa"
oncheckedchanged="RadioButton1_CheckedChanged"/>
<asp:RadioButton ID="RadioButton2" runat="server" Text="黑体" GroupName="aa"/>
</form>
</body>
其中后面那个radiobutton是我在radiobuttonlist不好用之后又重做的。
cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
/* protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Font=new Font(RadioButtonList1.SelectedValue,TextBox1.Font.Size);
}*/
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
TextBox1.Font = RadioButtonList1.SelectedValue;
}
}
另外,richtextbox是什么??我在网上看到,但是不会用
采纳答案后会追加10分的悬赏^_^ 展开
以下是我的代码:
aspx:
<body>
<form id="form1" runat="server">
<div>
</div>
请输入您希望的文字:
<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem>宋体</asp:ListItem>
<asp:ListItem>隶书</asp:ListItem>
<asp:ListItem>黑体</asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButton ID="RadioButton1" runat="server" Text="宋体" GroupName="aa"
oncheckedchanged="RadioButton1_CheckedChanged"/>
<asp:RadioButton ID="RadioButton2" runat="server" Text="黑体" GroupName="aa"/>
</form>
</body>
其中后面那个radiobutton是我在radiobuttonlist不好用之后又重做的。
cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
/* protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Font=new Font(RadioButtonList1.SelectedValue,TextBox1.Font.Size);
}*/
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
TextBox1.Font = RadioButtonList1.SelectedValue;
}
}
另外,richtextbox是什么??我在网上看到,但是不会用
采纳答案后会追加10分的悬赏^_^ 展开
1个回答
展开全部
aspx:
<body>
<form id="form1" runat="server">
<div>
</div>
请输入您希望的文字:
<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True" Text="宋体" GroupName="aa" oncheckedchanged="RadioButton_CheckedChanged"/>
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" Text="黑体" GroupName="aa" oncheckedchanged="RadioButton_CheckedChanged" />
</form>
</body>
cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
if (sender is RadioButton)
{
TextBox1.Font.Name = (sender as RadioButton).Text;
}
}
}
<body>
<form id="form1" runat="server">
<div>
</div>
请输入您希望的文字:
<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True" Text="宋体" GroupName="aa" oncheckedchanged="RadioButton_CheckedChanged"/>
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" Text="黑体" GroupName="aa" oncheckedchanged="RadioButton_CheckedChanged" />
</form>
</body>
cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
if (sender is RadioButton)
{
TextBox1.Font.Name = (sender as RadioButton).Text;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询