使用C#在ASPX页面中操作项目? [英] Manuplilating items in aspx page using C#?

查看:146
本文介绍了使用C#在ASPX页面中操作项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好;我在.aspx页面后面有一些C#代码陷入困境.我有一个带有字体系列选项(Times Roman,Courier,Comic Sans),asp文本框,asp标签和按钮对象的下拉列表.

现在必须要做的是:用户在文本框中输入文本,并从下拉列表中选择一个字体系列,当用户单击按钮时,Onclick事件将执行一个textchange事件,并且将显示在文本框中输入的文本.标签中选择的字体系列样式.

我的果酱:我不知道要使用哪种格式来更改C#的字体.
可以说下拉列表id="drop1"TextBox id="Text1"button onClick="Text_Change"Label id="label1"(没关系,我没有写确切的代码)
在摘要后面的代码中:

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);
}



我有一个使TextBox文本显示在Label中的单独方法,所以不必担心该步骤.
这是我不断在书本上和在网络上更改字体系列的格式.但是,我只是不知道他们如何使用它,因为它对我不起作用. .FontFamily未被编译器识别.是的,我拥有所有可以想象的名称空间.

我的问题:谁能向我解释如何使用C#代码更改标签的字体系列.没有JavaScript代码.并类似于更改字体大小和样式吗?

谢谢...非常感谢您提供很好的解释:)



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 :)

推荐答案

用于Web表单
For Web form
label1.Font.Name = "Times New Roman";



和赢的形式



And Win form

FontFamily ff = new FontFamily("Times New Roman");
Font f = new Font(ff, 10.0f);

label1.Font = f;



希望这能解决您的问题!



Hope this solve your problem!


尝试一下.

Try this.

FontFamily ff = new FontFamily("Times New Roman");
Font f = new Font(ff, 10.0f);

label1.Font = f;


这篇关于使用C#在ASPX页面中操作项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆