本文整理匯總了C#中System.Drawing.Color.FromArgb方法的典型用法代碼示例。如果您正苦於以下問題:C# Color.FromArgb方法的具體用法?C# Color.FromArgb怎麽用?C# Color.FromArgb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Color
的用法示例。
在下文中一共展示了Color.FromArgb方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: FromArgb1
public void FromArgb1(PaintEventArgs e)
{
Graphics g = e.Graphics;
// Transparent red, green, and blue brushes.
SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(120, 255, 0, 0));
SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(120, 0, 255, 0));
SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(120, 0, 0, 255));
// Base and height of the triangle that is used to position the
// circles. Each vertex of the triangle is at the center of one of the
// 3 circles. The base is equal to the diameter of the circles.
float triBase = 100;
float triHeight = (float)Math.Sqrt(3*(triBase*triBase)/4);
// Coordinates of first circle's bounding rectangle.
float x1 = 40;
float y1 = 40;
// Fill 3 over-lapping circles. Each circle is a different color.
g.FillEllipse(trnsRedBrush, x1, y1, 2*triHeight, 2*triHeight);
g.FillEllipse(trnsGreenBrush, x1 + triBase/2, y1 + triHeight,
2*triHeight, 2*triHeight);
g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2*triHeight, 2*triHeight);
}
示例2: FromArgb2
public void FromArgb2(PaintEventArgs e)
{
Graphics g = e.Graphics;
// Opaque colors (alpha value defaults to 255 -- max value).
Color red = Color.FromArgb(255, 0, 0);
Color green = Color.FromArgb(0, 255, 0);
Color blue = Color.FromArgb(0, 0, 255);
// Solid brush initialized to red.
SolidBrush myBrush = new SolidBrush(red);
int alpha;
// x coordinate of first red rectangle
int x = 50;
// y coordinate of first red rectangle
int y = 50;
// Fill rectangles with red, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, red);
g.FillRectangle(myBrush, x, y, 50, 100);
g.FillRectangle(myBrush, x, y + 250, 50, 50);
x += 50;
}
// x coordinate of first green rectangle.
x = 50;
// y coordinate of first green rectangle.
y += 50;
// Fill rectangles with green, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, green);
g.FillRectangle(myBrush, x, y, 50, 150);
x += 50;
}
// x coordinate of first blue rectangle.
x = 50;
// y coordinate of first blue rectangle.
y += 100;
// Fill rectangles with blue, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, blue);
g.FillRectangle(myBrush, x, y, 50, 150);
x += 50;
}
}
示例3: FromArgb3
public void FromArgb3(PaintEventArgs e)
{
Graphics g = e.Graphics;
// Opaque colors (alpha value defaults to 255 -- max value).
Color red = Color.FromArgb(255, 0, 0);
Color green = Color.FromArgb(0, 255, 0);
Color blue = Color.FromArgb(0, 0, 255);
// Solid brush initialized to red.
SolidBrush myBrush = new SolidBrush(red);
int alpha;
// x coordinate of first red rectangle
int x = 50;
// y coordinate of first red rectangle
int y = 50;
// Fill rectangles with red, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, red);
g.FillRectangle(myBrush, x, y, 50, 100);
g.FillRectangle(myBrush, x, y + 250, 50, 50);
x += 50;
}
// x coordinate of first green rectangle
x = 50;
// y coordinate of first green rectangle
y += 50;
// Fill rectangles with green, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, green);
g.FillRectangle(myBrush, x, y, 50, 150);
x += 50;
}
// x coordinate of first blue rectangle.
x = 50;
// y coordinate of first blue rectangle
y += 100;
// Fill rectangles with blue, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, blue);
g.FillRectangle(myBrush, x, y, 50, 150);
x += 50;
}
}
示例4: FromArgb4
public void FromArgb4(PaintEventArgs e)
{
Graphics g = e.Graphics;
// Transparent red, green, and blue brushes.
SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(0x78FF0000));
SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(0x7800FF00));
SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(0x780000FF));
// Base and height of the triangle that is used to position the
// circles. Each vertex of the triangle is at the center of one of the
// 3 circles. The base is equal to the diameter of the circles.
float triBase = 100;
float triHeight = (float)Math.Sqrt(3*(triBase*triBase)/4);
// coordinates of first circle's bounding rectangle.
float x1 = 40;
float y1 = 40;
// Fill 3 over-lapping circles. Each circle is a different color.
g.FillEllipse(trnsRedBrush, x1, y1, 2*triHeight, 2*triHeight);
g.FillEllipse(trnsGreenBrush, x1 + triBase/2, y1 + triHeight,
2*triHeight, 2*triHeight);
g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2*triHeight, 2*triHeight);
}
示例5: Color.FromArgb (int r, int g, int b)
//引入命名空間
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());
}
}
示例6: Color.FromArgb(100, Color.Blue)
//引入命名空間
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
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();
}
}
示例7: Color.FromArgb(77, color.R, color.G, color.B)
//引入命名空間
using System;
using System.Collections.Generic;
using System.ComponentModel;
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.java2s.com", 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());
}
}