Make(cnet) ver(4.04 build 185) Add(DLL,2953706,42,105) { ClassName="ColorPalette" Using=#18:System.Collections|21:System.ComponentModel|11:System.Data|14:System.Drawing|17:System.Reflection|20:System.Windows.Forms| Namespace="CommonControls" AccessModifier=1 Parent="System.Windows.Forms.UserControl" } Add(Inline,8715325,91,105) { Code=" // designer fields\r\n private System.ComponentModel.Container components = null;\r\n\r\n // internal fields\r\n private Bitmap _ColorPalette;\r\n private Color _ForeColor, _BackColor; /* the current selected foreground and background color */\r\n private int _ColorsPerColumn; /* the number of colors in a column */\r\n private Size _ColorSize; /* the size of a color rectangle */\r\n\r\n /// \r\n /// Creates a ColorPalette instance.\r\n /// \r\n public ColorPalette ()\r\n {\r\n // This call is required by the Windows.Forms Form Designer.\r\n InitializeComponent();\r\n SetStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);\r\n _ColorsPerColumn = 14;\r\n _ColorSize = new Size (12, 12);\r\n _ColorPalette = CreateColorPalette();\r\n }\r\n /// \r\n /// Gets or sets the current selected background color.\r\n /// \r\n public new Color BackColor {\r\n get { return _BackColor; }\r\n set { _BackColor = value; }\r\n }\r\n /// \r\n /// Gets or sets the number of colors displayed per row.\r\n /// \r\n public int ColorsPerColumn {\r\n get { return _ColorsPerColumn; }\r\n set {\r\n if (value > 0)\r\n {\r\n _ColorsPerColumn = value; \r\n _ColorPalette = CreateColorPalette();\r\n this.OnResize(EventArgs.Empty);\r\n }\r\n }\r\n }\r\n /// \r\n /// Gets or sets the size of each color.\r\n /// \r\n public Size ColorSize {\r\n get { return _ColorSize; }\r\n set {\r\n if ((value.Width > 0) && (value.Height > 0))\r\n {\r\n _ColorSize = value;\r\n _ColorPalette = CreateColorPalette();\r\n this.OnResize(EventArgs.Empty);\r\n }\r\n }\r\n }\r\n /// \r\n /// Gets or sets the current selected foreground color.\r\n /// \r\n public new Color ForeColor {\r\n get { return _ForeColor; }\r\n set { _ForeColor = value; }\r\n }\r\n\r\n /// \r\n /// Creates a bitmap containing the color palette.\r\n /// \r\n private Bitmap CreateColorPalette () {\r\n // local variables\r\n Bitmap bitmap;\r\n Rectangle rect;\r\n int bmp_width, bmp_height;\r\n PropertyInfo[] properties;\r\n ArrayList colors;\r\n Color color;\r\n SolidBrush brush;\r\n\r\n // get all colors defined as properties in the Color class\r\n properties = typeof (Color).GetProperties (BindingFlags.Public | BindingFlags.Static);\r\n colors = new ArrayList ();\r\n foreach (PropertyInfo prop in properties)\r\n {\r\n color = (Color) prop.GetValue (null, null);\r\n if (color == Color.Transparent) continue;\r\n if (color == Color.Empty) continue;\r\n // create brush of this color\r\n brush = new SolidBrush (color);\r\n colors.Add (brush);\r\n }\r\n // sort array\r\n colors.Sort (new _ColorSorter ());\r\n\r\n // calculate the width & height\r\n bmp_height = _ColorsPerColumn * _ColorSize.Height;\r\n bmp_width = (colors.Count / _ColorsPerColumn) * _ColorSize.Width;\r\n // if count colors does not exactly match an whole number of columns, then add an extra column to\r\n // the bitmap\r\n if ((colors.Count % _ColorsPerColumn) != 0) {\r\n bmp_width += _ColorSize.Width;\r\n }\r\n\r\n // create a base bitmap where each color is a square of 6x6 pixels\r\n bitmap = new Bitmap (bmp_width, bmp_height);\r\n using (Graphics g = Graphics.FromImage (bitmap)) {\r\n // initialize drawing\r\n g.Clear(Color.Black);\r\n rect = new Rectangle (0, 0, _ColorSize.Width, _ColorSize.Height);\r\n\r\n // iterate the colors and draw the color\r\n foreach (Brush b in colors) {\r\n g.FillRectangle (b, rect);\r\n // move down \r\n rect.Offset (0, _ColorSize.Height);\r\n if (rect.Bottom > bmp_height) {\r\n // move right\r\n rect.Location = new Point (rect.Left + _ColorSize.Width, 0);\r\n }\r\n }\r\n }\r\n\r\n // adjust the controls size\r\n Size = bitmap.Size;\r\n\r\n return bitmap;\r\n }\r\n /// \r\n /// Converts a client coordinate to a color based on the location on the color palette.\r\n /// \r\n private Color LocationToColor (Point point) {\r\n return _ColorPalette.GetPixel (point.X, point.Y);\r\n }\r\n\r\n /// \r\n /// Clean up any resources being used.\r\n /// \r\n protected override void Dispose (bool disposing) {\r\n if (disposing) {\r\n if (components != null) {\r\n components.Dispose ();\r\n }\r\n }\r\n base.Dispose (disposing);\r\n }\r\n\r\n #region Component Designer generated code\r\n /// \r\n /// Required method for Designer support - do not modify \r\n /// the contents of this method with the code editor.\r\n /// \r\n private void InitializeComponent()\r\n {\r\n // \r\n // ColorPalette\r\n // \r\n this.Name = "ColorPalette";\r\n this.Size = new System.Drawing.Size(64, 256);\r\n this.Resize += new System.EventHandler(this.ColorPalette_Resize);\r\n this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ColorPalette_MouseUp);\r\n this.Paint += new System.Windows.Forms.PaintEventHandler(this.ColorPalette_Paint);\r\n }\r\n #endregion\r\n\r\n /// \r\n /// Event fired when the control needs to be repainted.\r\n /// \r\n private void ColorPalette_Paint (object sender, System.Windows.Forms.PaintEventArgs e) {\r\n e.Graphics.DrawImageUnscaled (_ColorPalette, 0, 0);\r\n }\r\n /// \r\n /// Event fired when the mouse button is released over the control.\r\n /// \r\n private void ColorPalette_MouseUp (object sender, System.Windows.Forms.MouseEventArgs e) {\r\n // local variables\r\n Point point;\r\n\r\n point = new Point (e.X, e.Y);\r\n switch (e.Button) {\r\n case MouseButtons.Left : _ForeColor = LocationToColor (point); break;\r\n case MouseButtons.Right : _BackColor = LocationToColor (point); break;\r\n }\r\n }\r\n /// \r\n /// Event fired if the control is resized.\r\n /// \r\n private void ColorPalette_Resize (object sender, System.EventArgs e) {\r\n if (_ColorPalette != null) Size = _ColorPalette.Size;\r\n }\r\n\r\n \r\n /// \r\n /// The class _ColorSorter orders the colors based on the hue, saturation and brightness. This is the\r\n /// order that is also used by visual studio.\r\n /// \r\n internal class _ColorSorter: System.Collections.IComparer {\r\n\r\n #region IComparer Members\r\n\r\n public int Compare (object x, object y) {\r\n // local variables\r\n Color cx, cy;\r\n float hx, hy, sx, sy, bx, by;\r\n\r\n // get Color values\r\n cx = ((SolidBrush) x).Color;\r\n cy = ((SolidBrush) y).Color;\r\n \r\n if (cx.Equals(cy))\r\n return 0; \r\n\r\n // get saturation values\r\n sx = cx.GetSaturation ();\r\n sy = cy.GetSaturation ();\r\n // get hue values\r\n hx = cx.GetHue ();\r\n hy = cy.GetHue ();\r\n // get brightness values\r\n bx = cx.GetBrightness ();\r\n by = cy.GetBrightness ();\r\n\r\n // determine order\r\n // 1 : hue \r\n if (hx < hy) return -1; \r\n else if (hx > hy) return 1;\r\n else {\r\n // 2 : saturation\r\n if (sx < sy) return -1;\r\n else if (sx > sy) return 1;\r\n else {\r\n // 3 : brightness\r\n if (bx < by) return -1;\r\n else if (bx > by) return 1;\r\n else return 0;\r\n }\r\n }\r\n }\r\n\r\n #endregion\r\n\r\n }" } Add(AssemblyInfo,6907541,42,63) { References=#18:System.Drawing.dll|24:System.Windows.Forms.dll| Resources=#52:C:\HiAsm\Elements\CNET\Example\DLL\ColorPalette.resx| }