浏览代码

* ComboBox.cs: Set the initial value of the scrollbar to the
current index. Reduce the numbers of refreshs and IndexOfs
called.


svn path=/trunk/mcs/; revision=55661

Jackson Harper 20 年之前
父节点
当前提交
44835f976f

+ 5 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,8 @@
+2006-01-16  Jackson Harper  <[email protected]>
+
+	* ComboBox.cs: Set the initial value of the scrollbar to the
+	current index. Reduce the numbers of refreshs and IndexOfs called.
+
 2006-01-14  Alexander Olk  <[email protected]>
 
 	* FileDialog.cs: When the file listview is focused hitting the

+ 25 - 17
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs

@@ -1211,12 +1211,11 @@ namespace System.Windows.Forms
 		
 		private void UpdatedItems ()
 		{
-			if (dropdown_style != ComboBoxStyle.Simple)
-				return;				
-							
-			listbox_ctrl.UpdateLastVisibleItem ();
-			listbox_ctrl.CalcListBoxArea ();
-			listbox_ctrl.Refresh ();
+			if (listbox_ctrl != null) {
+				listbox_ctrl.UpdateLastVisibleItem ();
+				listbox_ctrl.CalcListBoxArea ();
+				listbox_ctrl.Refresh ();
+			}
 		}
 
 		#endregion Private Methods
@@ -1588,6 +1587,10 @@ namespace System.Windows.Forms
 										
 					vscrollbar_ctrl.Maximum = owner.Items.Count - (owner.DropDownStyle == ComboBoxStyle.Simple ? page_size : owner.maxdrop_items);
 					show_scrollbar = vscrollbar_ctrl.Visible = true;
+
+					int hli = GetHighLightedIndex ();
+					if (hli > 0)
+						vscrollbar_ctrl.Value = hli;
 				}
 				
 				Size = new Size (width, height);
@@ -1795,7 +1798,7 @@ namespace System.Windows.Forms
 					}
 				}
 			}
-			
+
 			private void OnKeyDownPUW (object sender, KeyEventArgs e) 			
 			{				
 				switch (e.KeyCode) {			
@@ -1822,27 +1825,29 @@ namespace System.Windows.Forms
 			
 			public void SetHighLightedItem (object item)
 			{
-				Rectangle invalidate;
+				Rectangle invalidate = Rectangle.Empty;
+				int hli;
 				
 				if (GetHighLightedItem () == item)
 					return;
 				
 				/* Previous item */
-    				if (GetHighLightedIndex () != -1) {    					
-					invalidate = GetItemDisplayRectangle (GetHighLightedIndex (), top_item);
-	    				if (ClientRectangle.IntersectsWith (invalidate))
-	    					Invalidate (invalidate);
+				hli = GetHighLightedIndex ();
+    				if (hli != -1) {    					
+					invalidate = GetItemDisplayRectangle (hli, top_item);
 	    			}
 				
     				highlighted_item = item;
     				
     				if (highlighted_item != null) {
 	    				 /* Current item */
-	    				invalidate = GetItemDisplayRectangle (GetHighLightedIndex (), top_item);
-	    				if (ClientRectangle.IntersectsWith (invalidate))
-	    					Invalidate (invalidate);
+	    				invalidate = Rectangle.Union (invalidate,
+							GetItemDisplayRectangle (GetHighLightedIndex (), top_item));
+	    				
 	    			}
-    				
+
+				if (ClientRectangle.IntersectsWith (invalidate))
+					Invalidate (invalidate);
 			}			
 
 			public void SetTopItem (int item)
@@ -1962,7 +1967,7 @@ namespace System.Windows.Forms
 					
 				SetHighLightedItem (owner.SelectedItem);
 				int index = GetHighLightedIndex ();
-				SetTopItem (index == -1 ? 0 : index );
+				top_item = (index == -1 ? 0 : index );
 				
 				CalcListBoxArea ();				
 				Show ();
@@ -1988,6 +1993,9 @@ namespace System.Windows.Forms
 			// Value Changed
 			private void VerticalScrollEvent (object sender, EventArgs e)
 			{				
+				if (top_item == vscrollbar_ctrl.Value)
+					return;
+
 				top_item =  vscrollbar_ctrl.Value;
 				UpdateLastVisibleItem ();
 				Refresh ();