change font style in c#

前端 未结 4 551
不思量自难忘°
不思量自难忘° 2020-12-12 00:42

hi there I want to change the font style of a label in an aspx page, through choosing options provided by a dorpdownlist. None of these methods work. I know I might be on th

4条回答
  •  眼角桃花
    2020-12-12 00:45

    here is my code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplication2
    {
        public partial class _Default : System.Web.UI.Page
        {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Font.Name = "Verdana";
        }
    }
    

    }

    and it is working, i just need you to make sure that before you run the application you set a fontname to your label because the fontname is empty when you put it in your page,(it doesnt work if you dont set a fontname initially) you need to set it then yuse the code i wrte above.open the properties window click the label and click font then choose a name for font name open the properties window click the label and click font then choose a name for font name

提交回复
热议问题