2010-07-21 6 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() 메서드를 호출합니다.