Csharp/C Sharp/2D Graphics/Color
Содержание
- 1 All the colors that are supported in C# according
- 2 Color Changer
- 3 Color.Chocolate
- 4 Create two color instances with different alpha components
- 5 Draw each of 100 cells with randomly chosen colors
- 6 Filled with the semi transparent and transparent color
- 7 Five yellow squares with different alpha values(Transparensy)
- 8 Get all known color
- 9 Known Colors
- 10 List all known color in a system
- 11 Transparent color
- 12 Use Color.FromArgb to create Color
All the colors that are supported in C# according
//ColorGuide.cs
/*
This Program will generate all the colors that are supported in C# according
to the Name....
I expected from you a better version of this program
If you can , then inform me how you made it
e.g. you make a dll file where the whole color array is stored then
your coding lines will decrease. I tried that way but the trial was
in vane....
*/
using System;
using System.Windows.Forms;
using System.Drawing;
public class CreateMyPanel : Form
{
Color[] color = new Color[]{
Color.AliceBlue, Color.AntiqueWhite, Color.Aqua, Color.Aquamarine,
Color.Azure, Color.Beige, Color.Bisque, Color.Black,
Color.BlanchedAlmond,Color.Blue, Color.BlueViolet,Color.Brown,
Color.BurlyWood, Color.CadetBlue, Color.Chartreuse,Color.Chocolate,
Color.Coral, Color.Cornsilk,Color.Crimson,
Color.Cyan, Color.DarkBlue, Color.DarkCyan,Color.DarkGoldenrod,
Color.DarkGray, Color.DarkGreen, Color.DarkKhaki,Color.DarkMagenta,
Color.DarkOliveGreen,Color.DarkOrange,Color.DarkOrchid,Color.DarkRed,
Color.DarkSalmon,Color.DarkSeaGreen,Color.DarkSlateBlue,Color.DarkSlateGray,
Color.DarkTurquoise,Color.DarkViolet,Color.DeepPink,Color.DeepSkyBlue,
Color.DimGray,Color.DodgerBlue,Color.Firebrick,Color.FloralWhite,
Color.ForestGreen,Color.Fuchsia,Color.Gainsboro,Color.GhostWhite,
Color.Gold,Color.Goldenrod,Color.Gray,Color.Green,Color.GreenYellow,
Color.Honeydew,Color.HotPink,Color.IndianRed,Color.Indigo,
Color.Ivory,Color.Khaki,Color.Lavender,Color.LavenderBlush,
Color.LawnGreen,Color.LemonChiffon,Color.LightBlue,Color.LightCoral,
Color.LightCyan,Color.LightGoldenrodYellow,Color.LightGray,
Color.LightGreen,Color.LightPink,Color.LightSalmon,Color.LightSeaGreen,
Color.LightSkyBlue,Color.LightSlateGray,Color.LightSteelBlue,
Color.LightYellow,Color.Lime,Color.LimeGreen,Color.Linen,
Color.Magenta,Color.Maroon,Color.MediumAquamarine,Color.MediumBlue,
Color.MediumOrchid,Color.MediumPurple,Color.MediumSeaGreen,
Color.MediumSlateBlue,Color.MediumSpringGreen,Color.MediumTurquoise,
Color.MediumVioletRed,Color.MidnightBlue,Color.MintCream,Color.MistyRose,
Color.Moccasin,Color.NavajoWhite,Color.Navy,Color.OldLace,
Color.Olive,Color.OliveDrab,Color.Orange,Color.OrangeRed,
Color.Orchid,Color.PaleGoldenrod,Color.PaleGreen,Color.PaleTurquoise,
Color.PaleVioletRed,Color.PapayaWhip,Color.PeachPuff,Color.Peru,
Color.Pink,Color.Plum,Color.PowderBlue,Color.Purple,Color.Red,
Color.RosyBrown,Color.RoyalBlue,Color.SaddleBrown,Color.Salmon,
Color.SandyBrown,Color.SeaGreen,Color.SeaShell,Color.Sienna,Color.Silver,
Color.SkyBlue,Color.SlateBlue,Color.SlateGray,Color.Snow,
Color.SpringGreen,Color.SteelBlue,Color.Tan,Color.Teal,
Color.Thistle,Color.Tomato,Color.Transparent,Color.Turquoise,
Color.Violet,Color.Wheat,Color.White,Color.WhiteSmoke,Color.Yellow,
Color.YellowGreen
};
private Panel panel1 = new Panel();
private Label[] col = new Label[140];
public CreateMyPanel()
{
// Initialize the Panel control.
panel1.Location = new Point(ClientRectangle.Left + 5,ClientRectangle.Top + 5);
panel1.Size = new Size(ClientRectangle.Right-5, ClientRectangle.Bottom-5);
panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.Controls.Add(panel1); // Add the Panel control to (inside) the form.
// Initalize the Label controls.
int ystart = ClientRectangle.Top;
for(int j=0; j<140; j++)
col[j] = new Label();
for(int i = 0; i<140; i++)
{
col[i].Size = new Size(ClientRectangle.Right, 20);
col[i].Font = new System.Drawing.Font("Comic Sans MS",10,FontStyle.Bold);
col[i].ForeColor = Color.Black;
if(col[i].Equals(Color.Black) == true)
{
col[i].ForeColor = Color.White;
}
col[i].Text = color[i].ToString();
col[i].Location = new Point(ClientRectangle.Left,ystart);
col[i].BackColor = color[i];
col[i].BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
panel1.Controls.Add(col[i]); // Add the Label controls to (inside) the Panel.
if((col[i].Location.Y > panel1.Location.Y))
{
panel1.AutoScroll = true;
}
ystart += 20;
}
this.Size = new Size(315, 300);
this.Text = "A Color Guide - JAYANT";
this.MaximizeBox = false;
// this.BorderStyle = FormBorderStyle.FixedDialog;
this.StartPosition = FormStartPosition.CenterScreen;
}
public static void Main()
{
Application.Run(new CreateMyPanel());
}
}
/* To Compile :----
csc /r:System.dll /r:System.Drawing.dll /r:System.Windows.Forms.dll /r:Microssft.Win32.InterOp.dll /out:ColorGuide.exe Colorguide.cs
*/
Color Changer
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace ColorChanger
{
public class ColorChanger : System.Windows.Forms.Form
{
internal System.Windows.Forms.Label lblSaturation;
internal System.Windows.Forms.Label lblHue;
internal System.Windows.Forms.Label lblBrightness;
internal System.Windows.Forms.Label Label1;
internal System.Windows.Forms.ListBox lstColors;
private System.ruponentModel.Container components = null;
public ColorChanger()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.lblSaturation = new System.Windows.Forms.Label();
this.lblHue = new System.Windows.Forms.Label();
this.lblBrightness = new System.Windows.Forms.Label();
this.Label1 = new System.Windows.Forms.Label();
this.lstColors = new System.Windows.Forms.ListBox();
this.SuspendLayout();
this.lblSaturation.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblSaturation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblSaturation.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblSaturation.Location = new System.Drawing.Point(264, 56);
this.lblSaturation.Name = "lblSaturation";
this.lblSaturation.Size = new System.Drawing.Size(136, 20);
this.lblSaturation.TabIndex = 9;
this.lblSaturation.Text = " Saturation";
this.lblHue.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblHue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblHue.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblHue.Location = new System.Drawing.Point(264, 32);
this.lblHue.Name = "lblHue";
this.lblHue.Size = new System.Drawing.Size(136, 20);
this.lblHue.TabIndex = 8;
this.lblHue.Text = " Hue";
this.lblBrightness.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblBrightness.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblBrightness.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblBrightness.Location = new System.Drawing.Point(264, 8);
this.lblBrightness.Name = "lblBrightness";
this.lblBrightness.Size = new System.Drawing.Size(136, 20);
this.lblBrightness.TabIndex = 7;
this.lblBrightness.Text = " Brightness";
this.Label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Label1.Location = new System.Drawing.Point(8, 8);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(200, 20);
this.Label1.TabIndex = 6;
this.Label1.Text = " Choose a Background Color:";
this.lstColors.Location = new System.Drawing.Point(8, 36);
this.lstColors.Name = "lstColors";
this.lstColors.Size = new System.Drawing.Size(200, 238);
this.lstColors.TabIndex = 5;
this.lstColors.SelectedIndexChanged += new System.EventHandler(this.lstColors_SelectedIndexChanged);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(472, 290);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.lblSaturation,
this.lblHue,
this.lblBrightness,
this.Label1,
this.lstColors});
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Name = "ColorChanger";
this.Text = "Color Changer";
this.Load += new System.EventHandler(this.ColorChanger_Load);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new ColorChanger());
}
private void ColorChanger_Load(object sender, System.EventArgs e)
{
string[] colorNames;
colorNames = System.Enum.GetNames(typeof(KnownColor));
lstColors.Items.AddRange(colorNames);
}
private void lstColors_SelectedIndexChanged(object sender, System.EventArgs e)
{
KnownColor selectedColor;
selectedColor = (KnownColor)System.Enum.Parse(typeof(KnownColor), lstColors.Text);
this.BackColor = System.Drawing.Color.FromKnownColor(selectedColor);
lblBrightness.Text = "Brightness = " +this.BackColor.GetBrightness().ToString();
lblHue.Text = "Hue = " + this.BackColor.GetHue().ToString();
lblSaturation.Text = "Saturation = " + this.BackColor.GetSaturation().ToString();
}
}
}
Color.Chocolate
using System;
using System.Drawing;
using System.Windows.Forms;
class PaintEvent
{
public static void Main()
{
Form form = new Form();
form.Text = "Paint Event";
form.Paint += new PaintEventHandler(MyPaintHandler);
Application.Run(form);
}
static void MyPaintHandler(object objSender, PaintEventArgs pea)
{
Graphics graphics = pea.Graphics;
graphics.Clear(Color.Chocolate);
}
}
Create two color instances with different alpha components
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
Color c1 = Color.FromArgb(100, Color.Blue);
Color c2 = Color.FromArgb(50, Color.Green);
g.FillEllipse(Brushes.Red, 20, 20, 80, 80);
g.FillRectangle(new SolidBrush(c1), 60, 80, 60, 60);
Point[] pa = new Point[] {
new Point(150, 40),
new Point(90, 40),
new Point(90, 120)};
g.FillPolygon(new SolidBrush(c2), pa);
}
public static void Main() {
Application.Run(new Form1());
}
}
Draw each of 100 cells with randomly chosen colors
using System;
using System.Drawing;
using System.Windows.Forms;
public class ColorChips : Form {
public ColorChips() {
Size = new Size(300,300);
Text = "Color Chips";
}
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
int h = DisplayRectangle.Height;
int w = DisplayRectangle.Width;
Random r = new Random();
for (int i = 0; i < 10; i++){
for (int j = 0; j < 10; j++) {
Color color = Color.FromArgb (r.Next(256), r.Next(256), r.Next(256));
Brush brush = new SolidBrush(color);
g.FillRectangle(brush, i*w/10, j*h/10, w/10, h/10);
}
}
base.OnPaint(e);
}
static void Main() {
Application.Run(new ColorChips());
}
}
Filled with the semi transparent and transparent color
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Text = "";
this.Resize += new System.EventHandler(this.Form1_Resize);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
Color c1 = Color.FromArgb(100, Color.Blue);
Color c2 = Color.FromArgb(50, Color.Green);
g.FillEllipse(Brushes.Red, 20, 20, 80, 80);
g.FillRectangle(new SolidBrush(c1), 60, 80, 60, 60);
Point[] pa = new Point[] {
new Point(150, 40),
new Point(90, 40),
new Point(90, 120)};
g.FillPolygon(new SolidBrush(c2), pa);
}
private void Form1_Resize(object sender, System.EventArgs e)
{
Invalidate();
}
}
Five yellow squares with different alpha values(Transparensy)
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g;
g = Graphics.FromHwnd(this.Handle);
g.FillRectangle(new SolidBrush(Color.Red), 10, 10, 210, 50);
//
Rectangle r = new Rectangle(40, 20, 30, 30);
Color c = Color.FromArgb(255, 255, 255, 0);
g.FillRectangle(new SolidBrush(c), r);
r.Offset(30, 0);
c = Color.FromArgb(200, 255, 255, 0);
g.FillRectangle(new SolidBrush(c), r);
r.Offset(30, 0);
c = Color.FromArgb(150, 255, 255, 0);
g.FillRectangle(new SolidBrush(c), r);
r.Offset(30, 0);
c = Color.FromArgb(100, 255, 255, 0);
g.FillRectangle(new SolidBrush(c), r);
r.Offset(30, 0);
c = Color.FromArgb(50, 255, 255, 0);
g.FillRectangle(new SolidBrush(c), r);
g.Dispose();
}
}
Get all known color
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form {
ArrayList knownColorList = new ArrayList();
ArrayList knownColorNameList = new ArrayList();
public Form1() {
NonSystemColors(knownColorList, knownColorNameList);
}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
private void NonSystemColors(ArrayList knownColorList, ArrayList knownColorNameList) {
Array cA = Enum.GetValues(typeof(KnownColor));
foreach (KnownColor knwnC in cA) {
Color curC = Color.FromKnownColor(knwnC);
if (!curC.IsSystemColor) {
knownColorList.Add(curC);
knownColorNameList.Add(curC.Name.ToString());
}
}
}
protected override void OnPaint(PaintEventArgs pea) {
Graphics g = pea.Graphics;
int wi = 70, hi = 12, rectNb = 8;
int count = knownColorList.Count;
this.Width = (wi + 2) * rectNb + 9;
int y = (int)(count / rectNb);
this.Height = y * (2 + hi) + 60;
DisplayKnownColors(g, count, wi, hi, rectNb);
g.Dispose();
}
private void DisplayKnownColors(Graphics g, int count, int wi, int hi, int rectNb) {
Rectangle rec;
Pen p = new Pen(this.ForeColor);
Brush b;
StringFormat strfmt = new StringFormat();
strfmt.LineAlignment = strfmt.Alignment = StringAlignment.Near;
int x, y;
for (int i = 0; i < count; i++) {
x = (int)(i % rectNb);
y = (int)(i / rectNb);
rec = new Rectangle(1 + x * (2 + wi), 1 + y * (2 + hi), wi, hi);
g.DrawRectangle(p, rec);
b = new SolidBrush((Color)knownColorList[i]);
g.FillRectangle(b, rec);
b = new SolidBrush(Color.Black);
g.DrawString((string)knownColorNameList[i], this.Font, b, rec, strfmt);
}
}
}
Known Colors
/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace KnownColors
{
/// <summary>
/// Summary description for KnownColors.
/// </summary>
public class KnownColors : System.Windows.Forms.Form
{
private System.Windows.Forms.ruboBox comboBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ruponentModel.Container components = null;
ArrayList cAL;
ArrayList cNAL;
public KnownColors()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.Text = "Known non-system colors";
cAL = new ArrayList(); // colors
cNAL = new ArrayList(); // strings
NonSystemColors(cAL, cNAL);
this.ruboBox1.Sorted = true;
this.ruboBox1.DataSource = cNAL; //set the combo"s data source
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ruboBox1 = new System.Windows.Forms.ruboBox();
this.SuspendLayout();
//
// comboBox1
//
this.ruboBox1.Location = new System.Drawing.Point(8, 8);
this.ruboBox1.Name = "comboBox1";
this.ruboBox1.Size = new System.Drawing.Size(121, 21);
this.ruboBox1.TabIndex = 0;
this.ruboBox1.Text = "comboBox1";
//
// KnownColors
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.ruboBox1});
this.Name = "KnownColors";
this.Text = "KnownColors";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new KnownColors());
}
private void NonSystemColors(ArrayList cAL, ArrayList cNAL)
{
Array cA = Enum.GetValues(typeof(KnownColor));
foreach(KnownColor knwnC in cA) // cX.Length = 167
{
Color curC = Color.FromKnownColor(knwnC);
if(!curC.IsSystemColor)
{
cAL.Add(curC);
cNAL.Add(curC.Name.ToString());
}
}
}
protected override void OnPaint(PaintEventArgs pea)
{
Graphics g = pea.Graphics;
int wi = 70, hi = 12, rectNb = 8;
int cALNb = cAL.Count;
this.Width = (wi +2)*rectNb + 9;
int y = (int)(cALNb / rectNb);
this.Height = y*(2 + hi) + 60;
DisplayKnownColors(g, cALNb, wi, hi, rectNb);
g.Dispose();
}
private void DisplayKnownColors(Graphics g, int cALNb, int wi, int hi, int rectNb)
{
Rectangle rec;
Pen p = new Pen(this.ForeColor);
Brush b;
StringFormat strfmt = new StringFormat();
strfmt.LineAlignment = strfmt.Alignment = StringAlignment.Near;
int x, y;
for (int i = 0; i < cALNb; i++)
{
x = (int)(i % rectNb);
y = (int)(i / rectNb);
rec = new Rectangle(1 + x*(2 + wi), 1 + y*(2 + hi), wi, hi);
g.DrawRectangle(p, rec);
b = new SolidBrush((Color)cAL[i]);
g.FillRectangle(b, rec);
b = new SolidBrush(Color.Black);
g.DrawString((string)cNAL[i], this.Font, b, rec, strfmt);
}
x = (int)(cALNb % rectNb);
y = (int)(cALNb / rectNb);
this.ruboBox1.Location = new Point(x*(wi + 2) + 2, y*(2 + hi) + 2);
}
}
}
List all known color in a system
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
private System.Windows.Forms.Label lblSaturation;
private System.Windows.Forms.Label lblHue;
private System.Windows.Forms.Label lblBrightness;
private System.Windows.Forms.Label Label1;
private System.Windows.Forms.ListBox lstColors;
public Form1()
{
InitializeComponent();
string[] colorNames = System.Enum.GetNames(typeof(KnownColor));
lstColors.Items.AddRange(colorNames);
}
private void lstColors_SelectedIndexChanged(object sender, EventArgs e)
{
KnownColor selectedColor = (KnownColor)System.Enum.Parse(typeof(KnownColor), lstColors.Text);
this.BackColor = System.Drawing.Color.FromKnownColor(selectedColor);
lblBrightness.Text = "Brightness = " + this.BackColor.GetBrightness().ToString();
lblHue.Text = "Hue = " + this.BackColor.GetHue().ToString();
lblSaturation.Text = "Saturation = " + this.BackColor.GetSaturation().ToString();
}
private void InitializeComponent()
{
this.lblSaturation = new System.Windows.Forms.Label();
this.lblHue = new System.Windows.Forms.Label();
this.lblBrightness = new System.Windows.Forms.Label();
this.Label1 = new System.Windows.Forms.Label();
this.lstColors = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// lblSaturation
//
this.lblSaturation.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblSaturation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblSaturation.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblSaturation.Location = new System.Drawing.Point(268, 57);
this.lblSaturation.Name = "lblSaturation";
this.lblSaturation.Size = new System.Drawing.Size(136, 20);
this.lblSaturation.TabIndex = 4;
this.lblSaturation.Text = " Saturation";
//
// lblHue
//
this.lblHue.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblHue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblHue.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblHue.Location = new System.Drawing.Point(268, 33);
this.lblHue.Name = "lblHue";
this.lblHue.Size = new System.Drawing.Size(136, 20);
this.lblHue.TabIndex = 3;
this.lblHue.Text = " Hue";
//
// lblBrightness
//
this.lblBrightness.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblBrightness.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lblBrightness.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.lblBrightness.Location = new System.Drawing.Point(268, 9);
this.lblBrightness.Name = "lblBrightness";
this.lblBrightness.Size = new System.Drawing.Size(136, 20);
this.lblBrightness.TabIndex = 2;
this.lblBrightness.Text = " Brightness";
//
// Label1
//
this.Label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Label1.Location = new System.Drawing.Point(12, 9);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(200, 20);
this.Label1.TabIndex = 0;
this.Label1.Text = " Choose a Background Color:";
//
// lstColors
//
this.lstColors.FormattingEnabled = true;
this.lstColors.Location = new System.Drawing.Point(12, 37);
this.lstColors.Name = "lstColors";
this.lstColors.Size = new System.Drawing.Size(200, 238);
this.lstColors.TabIndex = 1;
this.lstColors.SelectedIndexChanged += new System.EventHandler(this.lstColors_SelectedIndexChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(430, 284);
this.Controls.Add(this.lblSaturation);
this.Controls.Add(this.lblHue);
this.Controls.Add(this.lblBrightness);
this.Controls.Add(this.Label1);
this.Controls.Add(this.lstColors);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "Form1";
this.Text = "Color Changer";
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
Transparent color
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
public Form1() {
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Bitmap bitmap = new Bitmap("winter.jpg");
TextureBrush brush = new TextureBrush(bitmap);
e.Graphics.FillRectangle(brush, ClientRectangle);
bitmap.Dispose();
Color color = Color.Yellow;
int penWidth = 80;
Pen opaquePen = new Pen(color, penWidth);
e.Graphics.DrawLine(opaquePen, 0, 50, 200, 20);
opaquePen.Dispose();
Color semiTransparentColor = Color.FromArgb(128, color.R, color.G, color.B);
Pen semiTransparentPen = new Pen(semiTransparentColor, penWidth);
e.Graphics.DrawLine(semiTransparentPen, 0, 200, 200, 140);
semiTransparentPen.Dispose();
Color veryTransparentColor = Color.FromArgb(77, color.R, color.G, color.B);
Pen veryTransparentPen = new Pen(veryTransparentColor, penWidth);
e.Graphics.DrawLine(veryTransparentPen, 0, 350, 200, 260);
veryTransparentPen.Dispose();
Brush transparentBrush = new SolidBrush(semiTransparentColor);
e.Graphics.DrawString("www.nfex.ru", new Font("Verdana", 36, FontStyle.Bold),
transparentBrush, 80, 150);
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Alpha Blending";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
Use Color.FromArgb to create Color
using System;
using System.Drawing;
using System.Windows.Forms;
class RandomClear: Form
{
public static void Main()
{
Application.Run(new RandomClear());
}
public RandomClear()
{
Text = "Random Clear";
}
protected override void OnPaint(PaintEventArgs pea)
{
Graphics graphics = pea.Graphics;
Random rand = new Random();
graphics.Clear(Color.FromArgb(rand.Next(256),
rand.Next(256),
rand.Next(256)));
}
}