private Color getColorStyle(String s)
{
return (Color)Enum.Parse(typeof(KnownColor),s,true);
}
我传入了一个transparent,它报错说转换无效,请问这个怎么写?请各位帮个忙,我急用谢谢了
问题补充:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Array allcol = System.Enum.GetValues(typeof(KnownColor));
foreach (object hs in allcol)
{
string st = hs.ToString();
this.comboBox1.Items.AddRange(new object[] {});
}
}
private Color getColorStyle(String s)
{
return (Color)Enum.Parse(typeof(KnownColor),s,true);
}
void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
ComboBox myCombox = (ComboBox)sender;
Rectangle r = e.Bounds;
if (e.Index==-1)
{
return;
}
if (sender==null)
{
return;
}
r.Offset(2, 2);
r.Width = 50;
r.Offset(1, 1);
string displayText = this.comboBox1.Items[e.Index].ToString();
Color hs = this.getColorStyle(displayText);
using (SolidBrush myBrush=new SolidBrush(hs))
{
e.Graphics.FillRectangle(myBrush, r);
e.Graphics.DrawString(hs.Name, this.Font, new Brushes(this.ForeColor), e.Bounds.X + 26, e.Bounds.Y + 1);
}
}
}
}
洋-洋
|
初学一级
|
园豆:
160
提问于:2009-09-06 12:11