asp.net中设置下拉框,其中有四种颜色或者四种字体,选择其中一种,文本框中的颜色字体就随之改变
展开全部
protected void ddlColor_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ddlColor.SelectedValue == "红色")
{
this.txtMsg.ForeColor = Color.Red;//字体颜色
this.txtMsg.Font.Name= "仿宋_GB2312";//设置字体
this.txtMsg.Font.Size = FontUnit.Point(12);//字体大小
}
else if (this.ddlColor.SelectedValue == "黑色")
{
this.txtMsg.ForeColor = Color.Black;
this.txtMsg.Font.Size = FontUnit.Point(15);
this.txtMsg.Font.Name = "华文新魏";
}
else if (this.ddlColor.SelectedValue == "蓝色")
{
this.txtMsg.ForeColor = Color.Blue;
this.txtMsg.Font.Size = FontUnit.Point(20);
this.txtMsg.Font.Name = "方正舒体";
}
else if (this.ddlColor.SelectedValue == "绿色")
{
this.txtMsg.ForeColor = Color.Green;
this.txtMsg.Font.Size = FontUnit.Point(25);
this.txtMsg.Font.Name = "方正姚体";
}
}
注意:设置DropDownList 的AutoPostBack为true;
{
if (this.ddlColor.SelectedValue == "红色")
{
this.txtMsg.ForeColor = Color.Red;//字体颜色
this.txtMsg.Font.Name= "仿宋_GB2312";//设置字体
this.txtMsg.Font.Size = FontUnit.Point(12);//字体大小
}
else if (this.ddlColor.SelectedValue == "黑色")
{
this.txtMsg.ForeColor = Color.Black;
this.txtMsg.Font.Size = FontUnit.Point(15);
this.txtMsg.Font.Name = "华文新魏";
}
else if (this.ddlColor.SelectedValue == "蓝色")
{
this.txtMsg.ForeColor = Color.Blue;
this.txtMsg.Font.Size = FontUnit.Point(20);
this.txtMsg.Font.Name = "方正舒体";
}
else if (this.ddlColor.SelectedValue == "绿色")
{
this.txtMsg.ForeColor = Color.Green;
this.txtMsg.Font.Size = FontUnit.Point(25);
this.txtMsg.Font.Name = "方正姚体";
}
}
注意:设置DropDownList 的AutoPostBack为true;
追问
纠结了,就没有中简单点的方法呀
追答
这个我只是告诉你怎么在后台改变字体,你可以简化的啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询