LinearGradientMode.Horizontal, Vertical, BackwardDiagonal, ForwardDiagonal : LinearGradientBrush : Graphics C# Source Code


Custom Search

C# Source Code » Graphics » LinearGradientBrush »

 

LinearGradientMode.Horizontal, Vertical, BackwardDiagonal, ForwardDiagonal








    
 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Drawing2D;  

public class Form1 : System.Windows.Forms.Form {
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    protected override void OnPaint(PaintEventArgs e) {
        Graphics g = e.Graphics;
        Font f = new Font(new FontFamily("Times New Roman"), 10);
        Brush fb = new SolidBrush(Color.Black);
        LinearGradientBrush lGB;  
        Color cR = Color.Red, cW = Color.White;
        int w = 100, h = 70;

        g.DrawString("Horizontal", f, fb, 10, 5);
        Rectangle rec = new Rectangle(10, 20, w, h);
        LinearGradientMode lGM = LinearGradientMode.Horizontal;
        lGB = new LinearGradientBrush(rec, cR, cW, lGM);
        g.FillRectangle(lGB, rec);

        g.DrawString("Vertical", f, fb, w + 20, 5);
        rec.Offset(w + 10, 0);
        lGM = LinearGradientMode.Vertical;
        lGB = new LinearGradientBrush(rec, cR, cW, lGM);
        g.FillRectangle(lGB, rec);

        g.DrawString("ForwardDiagonal", f, fb, 10, h + 25);
        rec.Offset(-w - 10, h + 20);
        lGM = LinearGradientMode.ForwardDiagonal;
        lGB = new LinearGradientBrush(rec, cR, cW, lGM);
        g.FillRectangle(lGB, rec);

        g.DrawString("BackwardDiagonal", f, fb, w + 20, h + 25);
        rec.Offset(w + 10, 0);
        lGM = LinearGradientMode.BackwardDiagonal;
        lGB = new LinearGradientBrush(rec, cR, cW, lGM);
        g.FillRectangle(lGB, rec);

        fb.Dispose();
        g.Dispose();
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Graphics
» LinearGradientBrush