2011-10-07 61 views

回答

1

使用ComboBox1_DrawItem

protected void ComboBox1_DrawItem(object sender, 
    System.Windows.Forms.DrawItemEventArgs e) 
{ 

    float size = 0; 
    System.Drawing.Font myFont; 
    FontFamily font= null; 

    //Color and font based on index// 
    Brush brush; 
    switch(e.Index) 
    { 
     case 0: 
      size = 10; 
      brush = Brushes.Red; 
      family = font.GenericSansSerif; 
      break; 
     case 1: 
      size = 20; 
      brush = Brushes.Green; 
      font = font.GenericMonospace; 
      break; 
    } 

    myFont = new Font(font, size, FontStyle.Bold); 
    string text = ((ComboBox)sender).Items[e.Index].ToString(); 
    e.Graphics.DrawString(text, myFont, brush, e.Bounds.X, e.Bounds.Y); 
+0

我怎樣才能趕上組合框在數據網格視圖組合框列的事件? – Elmex

+0

DataGridViewComboBoxEditingControl類的文檔具有 一個示例,說明如何完全按照您的需要進行操作:http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxeditingcontrol.aspx它顯示瞭如何連接到網格中承載的 組合框上的SelectedIndexChanged事件。 –