不知道有没有这样的控件。在网上找了一下只找到一篇VB.net实现的代码,可我对VB.net的语法又不太懂。大家能不能给出一个C#实现方法?顺便问一下,VB.net有个Reflection.PropertyInfo,不知道做什么用的?我在MSDN上都没找到,因为有这样一段代码:
Dim pi As Reflection.PropertyInfo
        For Each pi In GetType(Color).GetProperties(Reflection.BindingFlags.Public Or Reflection.BindingFlags.Static)
            Me.ComboBox1.Items.Add(pi.Name)
        Next

解决方案 »

  1.   

    参看
    http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c88c.aspx#q547q
      

  2.   

    private Rectangle oldSelectedRect;
    private int oldSelectedIndex = -1;
    private void ComboBoxChange()
    {
    oldSelectedRect.X = -1;
    oldSelectedRect.Y = -1;
    oldSelectedRect.Width = 0;
    oldSelectedRect.Height = 0; this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
    this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
    this.comboBox1.ItemHeight = 20;
    comboBox1.Items.AddRange(new object[] { Color.Blue,
    Color.Red,
    Color.Green,
    Color.Aqua,
    Color.Pink,
    Color.Lavender});

    Location = new System.Drawing.Point(80, 100);
    TabIndex = 1;
    this.comboBox1.SelectedIndex = 2;
    this.comboBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(DrawComboItem);
    } public void DrawComboItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
    if( oldSelectedRect != e.Bounds &&
    oldSelectedIndex > -1 && oldSelectedIndex < comboBox1.Items.Count)
    {
    if(oldSelectedRect.Y != 3) //!=3 is hack to handle a drawing anomally
    e.Graphics.DrawRectangle(new Pen((Color) comboBox1.Items[oldSelectedIndex], 1), oldSelectedRect);
    } if( e.Index > -1 && e.Index < comboBox1.Items.Count)
    e.Graphics.FillRectangle(new SolidBrush( (Color)comboBox1.Items[e.Index] ), e.Bounds);

    if(comboBox1.SelectedIndex == e.Index)
    {
    e.Graphics.DrawRectangle(new Pen(Color.Black,1), e.Bounds);
    oldSelectedRect = e.Bounds;
    oldSelectedIndex = e.Index;
    }
    }
      

  3.   

    VB那个不是你想要的吧,那个refelection就是所谓的反射了,Color对象所有public和静态的属性名字都加到ComboBox1里面。
      

  4.   

    public void DrawComboItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
    if( oldSelectedRect != e.Bounds &&
    oldSelectedIndex > -1 && oldSelectedIndex < comboBox1.Items.Count)
    {
    if(oldSelectedRect.Y != 3) //!=3 is hack to handle a drawing anomally
    e.Graphics.DrawRectangle(new Pen((Color) comboBox1.Items[oldSelectedIndex], 1), oldSelectedRect);
    }
    }===========================================================================为什么这里oldSelectedRect.Y != 3 ?是什么含义
      

  5.   

    CF1.0 环境下没有 System.Windows.Forms.DrawItemEventArgs