如何使按钮文字变粗?

时间:2013-12-09 10:34:08

标签: c# winforms

我希望动态添加的按钮上的文字为粗体。我该怎么做?

这是我的代码:

var b = new Button()
{
    Location = new Point(x * 30, y * 30),
    Width = 30,
    Height = 30,
    Tag = new Point(y, x), // game location x, y
    BackColor = Color.SkyBlue,
};

3 个答案:

答案 0 :(得分:9)

Windows窗体:

var b = new Button()
{
    Location = new Point(x * 30, y * 30),
    //...
};
b.Font = new Font(b.Font.Name, b.Font.Size, FontStyle.Bold);

WPF:

var b = new Button()
{
    Location = new Point(x * 30, y * 30),
    //...
    FontWeight = FontWeights.Bold
};

ASP.NET

var b = new Button()
{
    Location = new Point(x * 30, y * 30),
    //...
};
b.Font.Bold = true;

答案 1 :(得分:5)

尝试此代码的最后一行:

var b = new Button()
{
    Location = new Point(x * 30, y * 30),
    Width = 30,
    Height = 30,
    Tag = new Point(y, x), // game location x, y
    BackColor = Color.SkyBlue,
    Font = new Font("Tahoma", 8.25F, FontStyle.Bold)
};

答案 2 :(得分:1)

Visual Basic中的通用格式为:

btn.Font = New Font("Font Name", Font Size, FontStyle.Bold)