using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class GradientPen: Form { public static void Main() { Application.Run(new GradientPen()); } public GradientPen() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { Brush lgbrush = new LinearGradientBrush( new Rectangle(0, 0, cx, cy), Color.White, Color.Black, LinearGradientMode.BackwardDiagonal); Pen pen = new Pen(lgbrush, Math.Min(cx, cy) / 25); pen.Alignment = PenAlignment.Inset; grfx.DrawRectangle(pen, 0, 0, cx, cy); grfx.DrawLine(pen, 0, 0, cx, cy); grfx.DrawLine(pen, 0, cy, cx, 0); } }
Author: coder
Two-Triangle Tile
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class TwoTriangleTile : Form { const int iSide = 50; // Side of square for triangle public static void Main() { Application.Run(new TwoTriangleTile()); } public TwoTriangleTile() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor, ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { Point[] apt = { new Point(0, 0), new Point(iSide, 0), new Point(0, iSide) }; PathGradientBrush pgbrush1 = new PathGradientBrush(apt, WrapMode.TileFlipXY); apt = new Point[] {new Point(iSide, 0), new Point(iSide, iSide), new Point(0, iSide)}; PathGradientBrush pgbrush2 = new PathGradientBrush(apt, WrapMode.TileFlipXY); grfx.FillRectangle(pgbrush1, 0, 0, cx, cy); grfx.FillRectangle(pgbrush2, 0, 0, cx, cy); } }
Square Tile
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class SquareTile: Form { const int iSide = 50; // Side of square public static void Main() { Application.Run(new SquareTile()); } public SquareTile() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { Point[] apt = {new Point(0, 0), new Point(iSide, 0), new Point(iSide, iSide), new Point(0, iSide)}; PathGradientBrush pgbrush = new PathGradientBrush(apt, WrapMode.TileFlipXY); pgbrush.SurroundColors = new Color[] { Color.Red, Color.Lime, Color.Blue, Color.White}; grfx.FillRectangle(pgbrush, 0, 0, cx, cy); } }
Triangle Tile
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class TriangleTile: Form { const int iSide = 50; // Side of square for triangle MenuItem miChecked; public static void Main() { Application.Run(new TriangleTile()); } public TriangleTile() { ResizeRedraw = true; Menu = new MainMenu(); Menu.MenuItems.Add("&Wrap-Mode"); foreach (WrapMode wm in Enum.GetValues(typeof(WrapMode))) { MenuItem mi = new MenuItem(); mi.Text = wm.ToString(); mi.Click += new EventHandler(MenuWrapModeOnClick); Menu.MenuItems[0].MenuItems.Add(mi); } miChecked = Menu.MenuItems[0].MenuItems[0]; miChecked.Checked = true; } void MenuWrapModeOnClick(object obj, EventArgs ea) { miChecked.Checked = false; miChecked = (MenuItem) obj; miChecked.Checked = true; Invalidate(); } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { Point[] apt = { new Point(0, 0), new Point(iSide, 0), new Point(0, iSide)}; PathGradientBrush pgbrush = new PathGradientBrush(apt, (WrapMode) miChecked.Index); grfx.FillRectangle(pgbrush, 0, 0, cx, cy); } }
Gradient Brush Ball
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class BouncingGradientBrushBall : Form { public static void Main() { Application.Run(new BouncingGradientBrushBall()); } public BouncingGradientBrushBall() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { GraphicsPath path = new GraphicsPath(); Rectangle rect = new Rectangle(10, 10, 30, 30); path.AddEllipse(rect); PathGradientBrush pgbrush = new PathGradientBrush(path); pgbrush.CenterPoint = new PointF((rect.Left + rect.Right) / 3, (rect.Top + rect.Bottom) / 3); pgbrush.CenterColor = Color.White; pgbrush.SurroundColors = new Color[] { Color.Red }; pea.Graphics.FillRectangle(pgbrush, rect); } }
Star Gradient Brush
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class StarGradientBrush: Form
{
public static void Main()
{
Application.Run(new StarGradientBrush());
}
public StarGradientBrush()
{
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs pea)
{
DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
}
protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
{
Point[] apt = new Point[5];
for (int i = 0; i < apt.Length; i++) { double dAngle = (i * 0.8 - 0.5) * Math.PI; apt[i] = new Point( (int)(cx * (0.50 + 0.48 * Math.Cos(dAngle))), (int)(cy * (0.50 + 0.48 * Math.Sin(dAngle)))); } PathGradientBrush pgbrush = new PathGradientBrush(apt); pgbrush.CenterColor = Color.White; pgbrush.SurroundColors = new Color[1] { Color.Black }; grfx.FillRectangle(pgbrush, 0, 0, cx, cy); } } [/csharp]
Triangle Gradient Brush
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class TriangleGradientBrush: Form { public static void Main() { Application.Run(new TriangleGradientBrush()); } public TriangleGradientBrush() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height); } protected void DoPage(Graphics grfx, Color clr, int cx, int cy) { Point[] apt = { new Point(cx, 0), new Point(cx, cy), new Point(0, cy) }; PathGradientBrush pgbrush = new PathGradientBrush(apt); grfx.FillRectangle(pgbrush, 0, 0, cx, cy); } }