【问题标题】:Make ListBoxItem look bold使 ListBoxItem 看起来粗体
【发布时间】:2014-02-28 20:46:48
【问题描述】:

我正在将由两个字符串组成的项目添加到列表框,一个来自 DropDownList,另一个来自 TextBox。我希望从 TextBox 中挑选的那个看起来很大胆。如何仅格式化 txtStaff.添加到 ListBox 后的文本。

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

【问题讨论】:

  • txtStaff.Text 的值是多少?你想怎么格式化?
  • 我只希望它在列表框中看起来 粗体
  • 你说你只想加粗文本框文本?
  • 恐怕你需要自己画图。设置 DrawMode = OwnerDraw 并更改 OnDrawItem() 中所需的任何内容。例如检查该问题:stackoverflow.com/questions/17276303/…
  • 更难!因为你只是得到一个 OnDrawItem!您需要对要使用不同字体的字符串部分进行标记 - 以便在绘图期间识别它:-(

标签: c# webforms listbox formatting


【解决方案1】:

试试看

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();
}

它可能会帮助你。

【讨论】:

  • All 使 TextBox 中的 txtStaff.Text 变为粗体,而不是 ListBox。
猜你喜欢
  • 2013-06-24
  • 1970-01-01
  • 2017-12-25
  • 2017-11-17
  • 2012-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-07
相关资源
最近更新 更多