Friday, 21 October 2011

HI there I want to change the font style of a label to either bold, italic, etc.. using a dropdownlist in an aspx page. Please let me know what I'm doing wrong here, because nothing seem to work. My Code

:
public void button_click(object sender, EventArgs e)
{
    var select= font1.SelectedItem.Value;
    if(select=="Bold")
    {
        // I have the following methods of doing this; None works for me.
        label1.Style["Font-Weight"]="bold";
        //I also tried this:
        label1.Font = new Font(label1.Font, FontStyle.Bold);
        //and this:
        this.label1.Font= new Font(this.label1.Font, FontStyle.Bold);
    }
}
When using .Font I get errors for invalid arguments, that the arguments for Font must be like this: Font(string, float). Also, keep in mind that the method of putting the actual size in the argument list is not what i want to do. Like this
label1.Font=new Font("Arial", 16, FontStyle.Bold);
//I don't want to change the font family or sixe of the label's text

No comments:

Post a Comment