[Mono-winforms-list] ColorDialog

kangaroo grompf@sublimeintervention.com
Sat, 19 Feb 2005 18:25:59 -0500


--Apple-Mail-1--448143394
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Alexander,

	I have attached a a patch that addresses a few major issues with 
ColorDialog; if you could please review and let me know if its ok to 
commit, it would be appreciated.

The issues are correlated:
	You are subclassing PictureBox and setting Image inside a OnPaint 
handler; setting the Image property calls Invalidate/Update; and this 
can cause an infinite repaint loop; I have removed this call in one 
case as it seems unecessary (BrightnessControl) and change it to be 
handled in the OnMouseUp in the other control.

	Invalidating while painting is generally a bad idea :)

Pleaes let me know

-kangaroo

--Apple-Mail-1--448143394
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="ColorDialog.diff"
Content-Disposition: attachment;
	filename=ColorDialog.diff

Index: System.Windows.Forms/ColorDialog.cs
===================================================================
--- System.Windows.Forms/ColorDialog.cs	(revision 40914)
+++ System.Windows.Forms/ColorDialog.cs	(working copy)
@@ -1699,12 +1699,10 @@
 			
 			protected override void OnPaint( PaintEventArgs e )
 			{
-				Draw( );
-				
 				base.OnPaint( e );
 			}
 			
-			private void Draw( )
+			private void UpdateBitmap ( )
 			{
 				Bitmap bmp = new Bitmap( drawingBitmap.Bitmap );
 				
@@ -1788,6 +1786,7 @@
 			{
 				mouseButtonDown = false;
 				drawCross = true;
+				UpdateBitmap ();
 				Invalidate( );
 				Update( );
 			}
@@ -1924,14 +1923,14 @@
 			
 			protected override void OnPaint( PaintEventArgs e )
 			{
-				Image = bitmap.Bitmap;
-				
 				base.OnPaint( e );
 			}
 			
 			protected override void OnMouseDown( MouseEventArgs e )
 			{
 				colorDialogPanel.TriangleControl.TrianglePosition = (int)( (float)( 189 - e.Y ) * step );
+				Invalidate ();
+				Update ();
 				
 				base.OnMouseDown( e );
 			}

--Apple-Mail-1--448143394--