可能重复:
在c#中更改字体样式
我希望将标签的字体样式更改为粗体,斜体等.使用aspx页面中的下拉列表.请让我知道我在这里做错了什么,因为似乎没什么用.
我的代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
使用.Font时,我得到无效参数的错误,Font的参数必须是这样的:Font(string,float).另外,请记住,将实际大小放在参数列表中的方法不是我想要做的.像这样
label1.Font=new Font("Arial", 16, FontStyle.Bold);
//I don't want to change the font family or sixe of the label's text
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有的,我陷入了困境.请赐教.谢谢
我有2个班级的学生班和StudentTest班.在我的Student课程中,我需要编写一个名为remove(int ID)的方法来从arraylist中删除具有特定ID的学生.该方法由StudentTest类中的main()方法调用.代码如下所示:
public class Student {
private final int size = 12; //max. size
private int [] ID = new int [size]; //the student's id number
private String [] name = new String [size]; //the student's name
private double [] tuition = new double [size];
int position= 0; //position to add data
//an add() method goes here, but is not the case of my question so I'm emitting it
//Here is the remove() to remove a student given their ID …Run Code Online (Sandbox Code Playgroud)