当前位置: 首页>>代码示例>>C#>>正文


C# Color.FromArgb方法代码示例

本文整理汇总了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);
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:25,代码来源:Color.FromArgb

示例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;
    }
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:54,代码来源:Color.FromArgb

示例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;
    }
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:54,代码来源:Color.FromArgb

示例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);
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:25,代码来源:Color.FromArgb

示例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());
  }
}
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:30,代码来源:Color.FromArgb

示例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();
    }
  }
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:53,代码来源:Color.FromArgb

示例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());
  }

}
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:68,代码来源:Color.FromArgb


注:本文中的System.Drawing.Color.FromArgb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。