Hi everyone; I'm in a jam with some C# code behind my .aspx page. I have a dropdownlist with font-family options (Times Roman, Courier, Comic Sans), an asp textbox,an asp label, and a button object.
Now What must be done is: The user enters text in the textbox, and selects a font-family from the dropdownlist, when the user click on the button the Onclick event performs a textchange event and the text which was entered in the textbox will appear in the label in whatever font-family style was chosen.
My jam: I have no idea which format to use to change the font-family for C#.
lets say the dropdownlist
id="drop1"
,
TextBox id="Text1"
,
button onClick="Text_Change"
, and
Label id="label1"
(Never mind that i did not write the exact code)
In Code behind snippet:
public void Text_Change(object sender, EventArgs e){
string f = drop1.SelectedItem.Value;
if(f== "Times Roman")
label1.FontFamily= new FontFamily("Times Roma);
}
I have a separate method for making the TextBox text appear in the Label so never mind that step.
This is the format for changing font family i keep getting in books, and on the web. However, I just don't know how they used it because it doesn't work for me. .FontFamily is not being recognize by the complier. Yes i have all namespaces imaginable.
My question: Can anyone please explain to me how to change the font-family of the label using C# code. No javascript code. And would it be similar to changing the font-size, and style?
Thanks...good explanations are very appreciated :)