我有要求,它的窗口窗体应用程序。我是C#的新手,需要您的帮助才能实现 SourceListbox和DestListbox以及四个按钮。 如何通过复制选定按钮的帮助将SourceListbox项目颜色更改为绿色,如果将其添加到另一个DestListBox中。 再次如果我从DestListbox中删除项目,该项目应该在SourceListbox中转到黑色。 有人可以帮我解决。如何更改列表框项目的颜色,如果它存在于另一个列表框中
我无法插入图片为便于理解
请参考下面 http://r4r.co.in/c1/01/tutorial/csharp/ListBox.shtml
链接酷似上面的例子。项目被添加到DestListBox后,源和目标列表框中匹配的项目应该在两个列表框中均为绿色文本。
下面的代码给第一项绿色, 但选择下一个项目只打算绿色,这是我不希望以后加入。
私人无效的button1_Click(对象发件人,EventArgs的){
foreach (string str in listBox1.SelectedItems)
{
listBox2.Items.Add(str);
SourceListbox.DrawMode = DrawMode.OwnerDrawVariable;// OwnerDrawFixed;
SourceListbox.DrawItem += s_lstbxChannel_DrawItem;
}
}
void s_lstbxChannel_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
bool isItemSelected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);
int itemIndex = e.Index;
if (itemIndex >= 0 && itemIndex < listBox1.Items.Count)
{
Graphics g = e.Graphics; // Background Color
SolidBrush backgroundColorBrush = new SolidBrush((isItemSelected) ? Color.White : Color.White);
g.FillRectangle(backgroundColorBrush, e.Bounds); // Set text color
string itemText = listBox1.Items[itemIndex].ToString();
SolidBrush itemTextColorBrush = (isItemSelected) ? new SolidBrush(Color.Green) : new SolidBrush(Color.Black);
g.DrawString(itemText, e.Font, itemTextColorBrush, listBox1.GetItemRectangle(itemIndex).Location);// Clean up
backgroundColorBrush.Dispose();
itemTextColorBrush.Dispose();
}
e.DrawFocusRectangle();
}
,其他用户可以编辑它变成你的问题。您的问题,因为它是非常不清楚..什么是SourceListbox和DestListbox,你使用winforms/wpf/asp.net? – Sayse 2014-09-24 07:42:59