Changeset 7538 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.cs
- Timestamp:
- 03/01/12 15:15:22 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ToolTipComboBox.cs
r7523 r7538 29 29 30 30 private ComboBoxState comboBoxState = ComboBoxState.Normal; 31 private bool mouseOver = false;32 31 33 32 public ToolTipComboBox() … … 36 35 SetStyle(ControlStyles.UserPaint, true); 37 36 InitializeComponent(); 38 DrawMode = System.Windows.Forms.DrawMode.OwnerDraw Variable;37 DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; 39 38 DropDownStyle = ComboBoxStyle.DropDownList; 40 }41 42 protected override void OnMeasureItem(MeasureItemEventArgs e) {43 base.OnMeasureItem(e);44 string text = GetItemText(Items[e.Index]);45 if (string.IsNullOrEmpty(text)) text = "test";46 var rect = TextRenderer.MeasureText(text, Font);47 e.ItemHeight = rect.Height - 2;48 e.ItemWidth = rect.Width;49 39 } 50 40 … … 72 62 } else { 73 63 using (var b = new SolidBrush(ForeColor)) { 74 Rectangle r = e.Bounds; 75 r.Offset(0, 1); 76 e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, r); 64 var rect = new Rectangle(2, 4, Size.Width - 2, Size.Height - 4); 65 e.Graphics.DrawString(GetItemText(Items[e.Index]), Font, b, rect); 77 66 } 78 67 } … … 84 73 base.OnPaint(e); 85 74 if (Enabled == false) comboBoxState = ComboBoxState.Disabled; 86 Rectangle clip = Bounds; // using e.ClipRectangle leads to strange behavior when maximizing/unmaximizing, just redraw the entire region all the time87 clip. Offset(-clip.X, -clip.Y); // x and y need to be 075 Rectangle clip = new Rectangle(new Point(0, 0), Size); 76 clip.Inflate(0, 1); 88 77 if (VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser) { 89 78 PushButtonState pb_State = PushButtonState.Normal; … … 109 98 ComboBoxRenderer.DrawDropDownButton(e.Graphics, r, comboBoxState); 110 99 } 111 Rectangle rect = clip; 112 rect.Inflate(-2, -4); 113 rect.Offset(1, 0); 100 var rect = new Rectangle(2, 4, Size.Width - 2, Size.Height - 4); 114 101 if (SelectedIndex > -1 && Items.Count > 0) { 115 102 using (var b = new SolidBrush(ForeColor)) { … … 141 128 protected override void OnMouseEnter(EventArgs e) { 142 129 base.OnMouseEnter(e); 143 mouseOver = true;144 130 if (comboBoxState == ComboBoxState.Normal) { 145 131 comboBoxState = ComboBoxState.Hot; … … 158 144 protected override void OnMouseLeave(EventArgs e) { 159 145 base.OnMouseLeave(e); 160 mouseOver = false;161 146 if (comboBoxState == ComboBoxState.Hot) { 162 147 comboBoxState = ComboBoxState.Normal; … … 167 152 protected override void OnMouseDown(MouseEventArgs e) { 168 153 base.OnMouseDown(e); 169 comboBoxState = ComboBoxState.Pressed; 170 Invalidate(); 154 if (e.Button == MouseButtons.Left) { 155 comboBoxState = ComboBoxState.Pressed; 156 Invalidate(); 157 } 171 158 } 172 159
Note: See TracChangeset
for help on using the changeset viewer.