<option value="a">111111</option>
<option value="b" selected>222222</option>
<option value="c">333333</option>
</select>
简陋了点 不过应该能实现 具体方法 通过js可以控制更多功能
listbox----><select size="10" multiple="MULTIPLE">
<option>1</option>
<option>2</option>
</select>
dropdowmlist------>
<select>
<option>1</option>
<option>2</option>
</select>
参见:https://www.it1352.com/532843.html
public Form1()
{
InitializeComponent()
listBox1.DrawMode = DrawMode.OwnerDrawFixed
listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem)
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground() //先调用基类实现
if (e.Index <0) //form load 的时候return
return
//因为此函数每一个 listItem drawing 都要调用, 所以不能简单的只写
//e.Graphics.DrawString(listBox1.Items[e.Index].ToString(),e.Font, Brushes.Red, e.Bounds)
//那样会造成所有item一个颜色
//这里是用item字符串是否包含某些词决定的 , 不好
if (listBox1.Items[e.Index].ToString().Contains(">>"))
{
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(),
e.Font, Brushes.Red, e.Bounds)
}
else if (listBox1.Items[e.Index].ToString().Contains("<<"))
{
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(),
e.Font, Brushes.Red, e.Bounds)
}
else
{
e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(),
e.Font, Brushes.Black, e.Bounds)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)