Advertisement
hk1

Color Shades and Tints

hk1
Feb 18th, 2014
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6.  
  7. namespace ColorShadesAndTints
  8. {
  9.     public partial class Form1 : Form
  10.     {
  11.         List<Color> colorList = new List<Color>();
  12.         Color myColor;
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.            
  17.         }
  18.  
  19.         private void Form1_Paint(object sender, PaintEventArgs e)
  20.         {
  21.             int l = 1;
  22.             int t = 40;
  23.             Graphics g = e.Graphics;
  24.             foreach (Color c in colorList) {
  25.                 using (SolidBrush b = new SolidBrush(c)) {
  26.                     g.FillRectangle(b, l, t, 30, 30);
  27.                     l = l + 30;
  28.                     if (l > 600)
  29.                     {
  30.                         l = 1;
  31.                         t = t + 30;
  32.                     }
  33.                 }
  34.             }
  35.         }
  36.  
  37.         private void button1_Click(object sender, EventArgs e)
  38.         {
  39.             ColorDialog c = new ColorDialog();
  40.             if (c.ShowDialog() == DialogResult.OK)
  41.             {
  42.                 myColor = c.Color;
  43.                 getShadesAndTints(myColor);
  44.                 Invalidate();
  45.             }
  46.         }
  47.  
  48.         private void getShadesAndTints(Color c)
  49.         {
  50.             int i; Double m;
  51.             int r; int g; int b;
  52.             for (i = 1; i < 21; i++)
  53.             {
  54.                 m = i * 0.1;
  55.                 r = (int)(c.R * m); if (r > 255) r = 255;
  56.                 g = (int)(c.G * m); if (g > 255) g = 255;
  57.                 b = (int)(c.B * m); if (b > 255) b = 255;
  58.                 colorList.Add(Color.FromArgb(r, g, b));
  59.             }
  60.         }
  61.  
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement