Index: /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.cs
===================================================================
--- /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.cs	(revision 7483)
+++ /branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.cs	(revision 7484)
@@ -29,4 +29,5 @@
 
     private ComboBoxState comboBoxState = ComboBoxState.Normal;
+    private bool mouseOver = false;
 
     public ToolTipComboBox()
@@ -35,33 +36,47 @@
       SetStyle(ControlStyles.UserPaint, true);
       InitializeComponent();
-      DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
+      DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
       DropDownStyle = ComboBoxStyle.DropDownList;
     }
 
+    protected override void OnMeasureItem(MeasureItemEventArgs e) {
+      base.OnMeasureItem(e);
+      string text = GetItemText(Items[e.Index]);
+      if (string.IsNullOrEmpty(text)) text = "test";
+      var rect = TextRenderer.MeasureText(text, Font);
+      e.ItemHeight = rect.Height - 2;
+      e.ItemWidth = rect.Width;
+    }
+
     protected override void OnDrawItem(DrawItemEventArgs e) {
+      base.OnDrawItem(e);
       var args = new ToolTipRequiredEventArgs(e.Index, Items[e.Index]);
       OnToolTipRequired(args);
       if (!e.State.HasFlag(DrawItemState.ComboBoxEdit) && !string.IsNullOrEmpty(args.ToolTip)) {
-        var ttRect = e.Graphics.MeasureString(args.ToolTip, Font);
+        var ttRect = TextRenderer.MeasureText(args.ToolTip, Font);
         if (RectangleToScreen(e.Bounds).Right + ttRect.Width > Screen.FromControl(this).Bounds.Right)
-          toolTip.Show(args.ToolTip, this, e.Bounds.Left - (int)Math.Ceiling(ttRect.Width), e.Bounds.Bottom);
+          toolTip.Show(args.ToolTip, this, e.Bounds.Left - ttRect.Width, e.Bounds.Bottom);
         else toolTip.Show(args.ToolTip, this, e.Bounds.Right, e.Bounds.Bottom);
       } else toolTip.Hide(this);
-      e.DrawBackground();
-      DrawItemText(e.Graphics, e.Bounds, e.Index);
+      if (!e.State.HasFlag(DrawItemState.ComboBoxEdit))
+        e.DrawBackground();
+      if (e.Index > -1 && Items.Count > 0) {
+        if (!e.State.HasFlag(DrawItemState.ComboBoxEdit) && e.State.HasFlag(DrawItemState.Selected)) {
+          using (var b = new SolidBrush(BackColor)) {
+            e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, e.Bounds);
+          }
+        } else if (!e.State.HasFlag(DrawItemState.ComboBoxEdit)) {
+          using (var b = new SolidBrush(ForeColor)) {
+            e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, e.Bounds);
+          }
+        } else {
+          using (var b = new SolidBrush(ForeColor)) {
+            Rectangle r = e.Bounds;
+            r.Offset(0, 1);
+            e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, r);
+          }
+        }
+      }
       e.DrawFocusRectangle();
-      base.OnDrawItem(e);
-    }
-    protected override void OnDropDownClosed(EventArgs e) {
-      base.OnDropDownClosed(e);
-      toolTip.Hide(this);
-    }
-
-    private void DrawItemText(Graphics graphics, Rectangle rectangle, int index) {
-      if (index == -1 || Items.Count == 0)
-        return;
-      using (var b = new SolidBrush(ForeColor)) {
-        graphics.DrawString(GetItemText(Items[index]), Font, b, rectangle);
-      }
     }
 
@@ -69,4 +84,6 @@
       base.OnPaint(e);
       if (Enabled == false) comboBoxState = ComboBoxState.Disabled;
+      Rectangle clip = Bounds; // using e.ClipRectangle leads to strange behavior when maximizing/unmaximizing, just redraw the entire region all the time
+      clip.Offset(-clip.X, -clip.Y); // x and y need to be 0
       if (VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser) {
         PushButtonState pb_State = PushButtonState.Normal;
@@ -77,24 +94,27 @@
         else if (comboBoxState == ComboBoxState.Pressed)
           pb_State = PushButtonState.Pressed;
-        Rectangle r = e.ClipRectangle;
-        r.Inflate(1, 1);
-        ButtonRenderer.DrawButton(e.Graphics, r, pb_State);
-        r = new Rectangle(e.ClipRectangle.Right - SystemInformation.VerticalScrollBarWidth + 2,
-                                    e.ClipRectangle.Top,
+
+        ButtonRenderer.DrawButton(e.Graphics, clip, pb_State);
+        var r = new Rectangle(clip.Right - SystemInformation.VerticalScrollBarWidth + 2,
+                                    clip.Top,
                                     SystemInformation.VerticalScrollBarWidth - 4,
-                                    e.ClipRectangle.Height);
+                                    clip.Height);
         DrawArrow(e.Graphics, r);
       } else {
-        ComboBoxRenderer.DrawTextBox(e.Graphics, e.ClipRectangle, comboBoxState);
-        Rectangle r = new Rectangle(e.ClipRectangle.Right - SystemInformation.VerticalScrollBarWidth,
-                                    e.ClipRectangle.Top,
+        ComboBoxRenderer.DrawTextBox(e.Graphics, clip, comboBoxState);
+        var r = new Rectangle(clip.Right - SystemInformation.VerticalScrollBarWidth,
+                                    clip.Top,
                                     SystemInformation.VerticalScrollBarWidth,
-                                    e.ClipRectangle.Height);
+                                    clip.Height);
         ComboBoxRenderer.DrawDropDownButton(e.Graphics, r, comboBoxState);
       }
-      Rectangle rect = e.ClipRectangle;
+      Rectangle rect = clip;
       rect.Inflate(-2, -4);
       rect.Offset(1, 0);
-      DrawItemText(e.Graphics, rect, SelectedIndex);
+      if (SelectedIndex > -1 && Items.Count > 0) {
+        using (var b = new SolidBrush(ForeColor)) {
+          e.Graphics.DrawString(GetItemText(Items[SelectedIndex]), Font, b, rect);
+        }
+      }
     }
 
@@ -106,12 +126,41 @@
     }
 
+    protected override void OnDropDown(EventArgs e) {
+      base.OnDropDown(e);
+      comboBoxState = ComboBoxState.Pressed;
+      Invalidate();
+    }
+
+    protected override void OnDropDownClosed(EventArgs e) {
+      base.OnDropDownClosed(e);
+      toolTip.Hide(this);
+      comboBoxState = ComboBoxState.Normal;
+      Invalidate();
+    }
+
     protected override void OnMouseEnter(EventArgs e) {
       base.OnMouseEnter(e);
-      comboBoxState = ComboBoxState.Hot;
+      mouseOver = true;
+      if (comboBoxState == ComboBoxState.Normal) {
+        comboBoxState = ComboBoxState.Hot;
+        Invalidate();
+      }
+    }
+
+    protected override void OnMouseHover(EventArgs e) {
+      base.OnMouseHover(e);
+      if (comboBoxState == ComboBoxState.Normal) {
+        comboBoxState = ComboBoxState.Hot;
+        Invalidate();
+      }
     }
 
     protected override void OnMouseLeave(EventArgs e) {
       base.OnMouseLeave(e);
-      comboBoxState = ComboBoxState.Normal;
+      mouseOver = false;
+      if (comboBoxState == ComboBoxState.Hot) {
+        comboBoxState = ComboBoxState.Normal;
+        Invalidate();
+      }
     }
 
@@ -119,11 +168,5 @@
       base.OnMouseDown(e);
       comboBoxState = ComboBoxState.Pressed;
-    }
-
-    protected override void OnMouseUp(MouseEventArgs e) {
-      base.OnMouseUp(e);
-      if (Top <= e.Y && Bottom >= e.Y && Left < e.X && Right > e.X)
-        comboBoxState = ComboBoxState.Hot;
-      else comboBoxState = ComboBoxState.Normal;
+      Invalidate();
     }
 
