Subversion Repositories AndroidProjects

Rev

Rev 809 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;

using System.Runtime.InteropServices;

namespace ColorPicker
{
    public partial class ColorWidget: UserControl
    {
        private Bitmap mGradientBox = null;

        public ColorWidget()
        {
            InitializeComponent();

            mGradientBox = new Bitmap(200, 200);
            Rectangle rect = new Rectangle(0, 0, 200, 200);
            BitmapData data = mGradientBox.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            IntPtr ptr = data.Scan0;
            int bytes = data.Stride * mGradientBox.Height;
            var rgbValues = new byte[bytes];

            for (int i = 0; i < bytes; i++)
            {
                rgbValues[i] = (byte)((i * 255) / (3 * bytes));
            }

            Marshal.Copy(rgbValues, 0, ptr, bytes);
           
            mGradientBox.UnlockBits(data);
        }

        private void colorWheelBox_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.DrawString("This is a diagonal line drawn on the control", new Font("Arial", 10), System.Drawing.Brushes.Blue, new Point(30, 30));

            g.DrawLine(System.Drawing.Pens.Red, colorWheelBox.Left, colorWheelBox.Top, colorWheelBox.Right, colorWheelBox.Bottom);

            Rectangle rect = new Rectangle(10, 10, Width - 20, Height - 20);

            g.DrawImage(mGradientBox, rect);
        }
    }
}