我正在将包含两个字符串的项目添加到DropDownList中的列表框,另一个来自TextBox。我希望从TextBox中挑选的那个看起来很大胆。我怎样才能格式化txtStaff。添加到ListBox后的文本。
ListBox1.Items.Add(ddlFilter.SelectedItem.Text + " " + txtStaff.Text);
答案 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();
}
它可能对你有所帮助。