使ListBoxItem看起来粗体

时间:2014-02-28 12:13:44

标签: c# webforms listbox formatting

我正在将包含两个字符串的项目添加到DropDownList中的列表框,另一个来自TextBox。我希望从TextBox中挑选的那个看起来很大胆。我怎样才能格式化txtStaff。添加到ListBox后的文本。

ListBox1.Items.Add(ddlFilter.SelectedItem.Text + " " + txtStaff.Text);

1 个答案:

答案 0 :(得分:0)

试试吧

txtStaff.Font.Bold = True;

使用 css

<强> CSS

.highlight
{
  font-weight:bold;
}

<强>码

txtStaff.CssClass = "highlight";

txtStaff.Attributes["style"] = "font-weight:bold;";

修改: -

我不确定但是试试。

ListBox1.Items.Add(ddlFilter.SelectedItem.Text + " " + txtStaff.Text);
ListBox1.DrawMode = DrawMode.OwnerDrawFixed;
private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    e.DrawBackground();
    e.Graphics.DrawString(ListBox1.Items[e.Index].ToString(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, e.Bounds);
    e.DrawFocusRectangle();
}

它可能对你有所帮助。