2 // System.Windows.Forms.ColorDialog.cs
5 // stubbed out by Jaak Simm (jaaksimm@firm.ee)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
9 // (C) Ximian, Inc., 2002
13 using System.Runtime.InteropServices;
15 namespace System.Windows.Forms {
18 /// Represents a common dialog box that displays available colors along with controls that allow the user to define custom colors.
21 public class ColorDialog : CommonDialog {
23 private bool allowFullOpen;
24 private bool anyColor;
26 private int[] customColors;
27 private bool fullOpen;
28 private bool showHelp;
29 private bool solidColorOnly;
31 public ColorDialog() : base()
36 // these are show to be in the ms implmentation by winchurn
37 // but are not valid since they are not abstract or have any accessors.
38 //protected virtual IntPtr Instance { }
39 //protected virtual int Options { }
41 public virtual bool AllowFullOpen {
46 allowFullOpen = value;
50 public virtual bool AnyColor {
68 public int[] CustomColors {
73 if ( value != null ) {
74 for ( int i = 0; i < Math.Min ( customColors.Length, value.Length ); i++ )
75 customColors [ i ] = value [ i ];
80 public virtual bool FullOpen {
89 public virtual bool ShowHelp {
98 public virtual bool SolidColorOnly {
100 return solidColorOnly;
103 solidColorOnly = value;
107 public override void Reset()
109 allowFullOpen = true;
113 customColors = new int [ 16 ];
114 for ( int i = 0; i < customColors.Length; i++ )
115 customColors [ i ] = Win32.RGB ( Color.White );
119 solidColorOnly = false;
122 protected override bool RunDialog( IntPtr hwndOwner )
124 CHOOSECOLOR cc = new CHOOSECOLOR ( );
125 cc.hwndOwner = hwndOwner;
126 cc.lStructSize = ( uint ) Marshal.SizeOf( cc );
127 cc.Flags = (int) ( ChooseColorFlags.CC_RGBINIT | ChooseColorFlags.CC_ENABLEHOOK );
129 cc.lpfnHook = new Win32.FnHookProc ( this.HookProc );
131 if ( AllowFullOpen ) {
133 cc.Flags |= (int) ChooseColorFlags.CC_FULLOPEN;
135 else cc.Flags |= (int) ChooseColorFlags.CC_PREVENTFULLOPEN;
138 cc.Flags |= (int) ChooseColorFlags.CC_ANYCOLOR;
141 cc.Flags |= (int) ChooseColorFlags.CC_SHOWHELP;
143 if ( SolidColorOnly )
144 cc.Flags |= (int) ChooseColorFlags.CC_SOLIDCOLOR;
146 cc.rgbResult = Win32.RGB ( Color );
148 cc.lpCustColors = Marshal.AllocHGlobal ( Marshal.SizeOf( customColors[0] ) * customColors.Length );
149 Marshal.Copy ( customColors, 0, cc.lpCustColors, customColors.Length );
153 res = Win32_WineLess.ChooseColor ( ref cc );
156 this.Color = Color.FromArgb ( cc.rgbResult );
157 Marshal.Copy ( cc.lpCustColors, customColors, 0, customColors.Length );
161 Marshal.FreeHGlobal ( cc.lpCustColors );
167 public override string ToString()
169 return GetType( ).FullName.ToString ( ) + ", Color: " + Color.ToString ( );