类似图层控件下拉 AutoCAD 。
感谢。
答案 0 :(得分:0)
我自己解决了......
我创建了一个继承组合框类的用户控件,这个控件对我来说就像普通的组合框一样正常。
这是一段代码,可以帮助您了解有关此控件的更多信息。
公共部分类下拉列表:ComboBox
{
public dropdown()
{
this.DrawMode = DrawMode.OwnerDrawVariable;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
// Make sure we're not trying to draw something that isn't there.
if (e.Index >= this.Items.Count || e.Index <= -1)
return;
// Get the item object.
object item = this.Items[e.Index];
if (item == null)
return;
// Draw the background color depending on
// if the item is selected or not.
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
// The item is selected.
// We want a blue background color.
e.Graphics.FillRectangle(new SolidBrush(Color.Moccasin), e.Bounds);
}
else
{
// The item is NOT selected.
// We want a white background color.
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
}
if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
{
e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
}
// Draw the items...
LayerEdit le = (LayerEdit)item;
string text = le.LayerName.ToString();
SizeF stringSize = e.Graphics.MeasureString(text, this.Font);
// Draw layer visible(on/off)...
e.Graphics.DrawImage(byteArrayToImage(le.Visible), 2, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 14, 14);
// Draw layer Lock...
e.Graphics.DrawImage(byteArrayToImage(le.Lock), 18, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 15, 14);
// Draw layer plot...
e.Graphics.DrawImage(byteArrayToImage(le.Plot), 37, 1 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 14, 14);
// Draw layer color...
Brush brush = new SolidBrush(ColorTranslator.FromHtml(le.ColourValue));
e.Graphics.FillRectangle(brush, 55, 4 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 10, 10);
e.Graphics.DrawRectangle(Pens.Black, 55, 4 + e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2, 10, 10);
// Draw layer name...
e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.Black), new PointF(68, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2));
}
//convert bytes into image...
public Image byteArrayToImage(byte[] byteArrayIn)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}