2010-07-21 83 views
0

我有一個組合框具有自定義繪製的項目。它也利用斑馬條紋,因此,懸停顏色有時會關閉。我怎樣才能控制它在懸停上的外觀?爲組合框中的列表項懸停的字體顏色

這是我使用的代碼:

Color zeros = Color.FromArgb(200, 200, 200); 
    Color ones = Color.FromArgb(225, 225, 255); 
    private void innerBox_DrawItem(object sender, DrawItemEventArgs e) { 
     Brush brush = new SolidBrush(e.ForeColor); 
     Pen pen = new Pen(e.ForeColor); 


     if (e.Index % 2 == 0) { 
      Brush backgroundBrush = new SolidBrush(zeros); 
      e.Graphics.FillRectangle(backgroundBrush, e.Bounds); 
     } else { 
      Brush backgroundBrush = new SolidBrush(ones); 
      e.Graphics.FillRectangle(backgroundBrush, e.Bounds); 
     } 

     Tenant tenant = ((ComboBox)sender).Items[e.Index] as Tenant; 

     Rectangle rect = e.Bounds; 

     //Draw Tenant Name 
     if (tenant.TenantName != null) { 
      e.Graphics.DrawString(tenant.TenantName, e.Font, brush, rect, StringFormat.GenericDefault); 
     } 
     rect.X += MaxTenantLength; 
     e.Graphics.DrawLine(pen, new Point(rect.X - 3, rect.Y), new Point(rect.X - 3, rect.Y + e.Bounds.Height)); 

     //Draw Property 
     if (tenant.Property != null) { 
      e.Graphics.DrawString(tenant.Property.PropertyName, e.Font, brush, rect, StringFormat.GenericDefault); 
     } 
     rect.X += MaxPropertyLength; 
     e.Graphics.DrawLine(pen, new Point(rect.X - 3, rect.Y), new Point(rect.X - 3, rect.Y + e.Bounds.Height)); 

     //Draw Rental Unit 
     if (tenant.RenatlUnit != null) { 
      e.Graphics.DrawString(tenant.RenatlUnit.UnitNumber, e.Font, brush, rect, StringFormat.GenericDefault); 
     } 
     rect.X += MaxRentalUnitLength; 

     e.DrawFocusRectangle(); 
    } 

回答

0

捕獲MouseMove事件,並創建某種成員變量作爲一個標誌,如果鼠標在條紋「斑馬」項目。如有必要,調用Refresh()方法。