[英]Change Font Style
I have a label with text in Bold and Italic .我有一个带有Bold和Italic文本的标签。 I want to change those font properties through a button click.
我想通过单击按钮来更改这些字体属性。
I got to know of the code Label1.Font = new Font(Label1.Font, FontStyle.Regular);
我知道了代码
Label1.Font = new Font(Label1.Font, FontStyle.Regular);
But from this code it will undo both BOLD & ITALIC properties.但是从这段代码中,它将撤消BOLD和ITALIC属性。 I want only to remove bold property.....
我只想删除粗体属性.....
Are there anything like fontsyle.bold = false
?有没有类似
fontsyle.bold = false
东西?
在创建新字体时使用原始字体的Font.Style ,使用& ~
翻转样式
label1.Font = new Font(label1.Font, label1.Font.Style & ~FontStyle.Bold);
The best option is to use bitcodes and the XOR operator ^ 最好的选择是使用bitcodes和XOR运算符^
try this code: 试试这段代码:
Label1.Font = new Font(Label1.Font.Style ^ FontStyle.Regular);
private void btn_bold_CheckedChanged(object sender, EventArgs e)
{
label1.Font = label2.Font = new Font( label1.Font,label1.Font.Style ^ FontStyle.Bold);
}
private void btn_italic_Click(object sender, EventArgs e)
{
label1.Font = label2.Font = new Font(label1.Font, label1.Font.Style ^ FontStyle.Italic);
}
private void btn_underline_Click(object sender, EventArgs e)
{
label1.Font = label2.Font = new Font(label1.Font, label1.Font.Style ^ FontStyle.Underline);
}
This will do all what do u want这将做你想做的一切
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.