1.先上实例:
lable1.Font = new Font("微软雅黑", 9);
对象.Font = new Font("字体",属性。。。。。)
2.看看其本质
public Font (
FontFamily family,
float emSize,
FontStyle style
)
3.参数说明
family
新 Font 的 FontFamily。
emSize
新字体的全身大小(以磅值为单位)。
style
新字体的 FontStyle。
第三个参数就是用来设置字体样式的,FontStyle是个枚举类型,可以从MSDN里查到它的说明如下:
FontStyle 枚举
指定应用到文本的字形信息。
此枚举有一个 FlagsAttribute 属性,允许其成员值按位组合。
而它的成员如下:
成员名称 说明
Bold 加粗文本。
Italic 倾斜文本。
Regular 普通文本。
Strikeout 中间有直线通过的文本。
Underline 带下划线的文本。
//那么,只需要将第三个参数,把 Bold 和 Italic 组合起来就可以了。
textBox1.Text= new Font( "宋体", 15, textBox1.Font.style); //保持textBox1中的文字字形,将字体设置为宋体、15
textBox1.Font=new Font(textBox1.Font,FontStyle.Bold | FontStyle.Italic );
FontStyle.Bold | FontStyle.Italic// .这里是粗斜体
//如果我想除掉斜体呢,那么
~FontStyle.Italic
oldFont.Style& ~FontStyle.Bold //字形取与操作。