Mega Code Archive

 
Categories / C# / 2D Graphics
 

Transparent color

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.rntsoft.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());   } }