change font style in c#

前端 未结 4 553
不思量自难忘°
不思量自难忘° 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 01:00

    On web we do not create new Font this works for desktop programming and the new Font are made on server not on client.

    The Label contains the .Font but not to set a new font, but to actually create a new inline style, and the object is the FontInfo (not the Font).

    From MSDN FontInfo here is an example:

    // Note that myLabel.Font is a FontInfo object.
    
    myLabel.Font.Bold = true;
    myLabel.Font.Italic = false;
    myLabel.Font.Name = "verdana";
    myLabel.Font.Overline = false;
    myLabel.Font.Size = 10;
    myLabel.Font.Strikeout = false;
    myLabel.Font.Underline = true;
    
    // Write information on the FontInfo object to the myLabel label.
    myLabel.Text = myLabel.Font.ToString();
    

    The final render of this contains inline style to give this properties to the text that is inside a span or a div. Is better of course to give a global css class, but some times you need to interfere with inline style.

提交回复
热议问题