Matrix Draw : Matrix « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » MatrixScreenshots 
Matrix Draw
Matrix Draw

/*
GDI+ Programming in C# and VB .NET
by Nick Symmonds

Publisher: Apress
ISBN: 159059035X
*/

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

namespace MatrixDraw_c
{

  public class MatrixDraw : System.Windows.Forms.Form
    {
    internal System.Windows.Forms.HScrollBar rotate;
    internal System.Windows.Forms.VScrollBar xlate;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

    int XlateY;
    float Angle;
    Rectangle DrawingRect = new Rectangle(2525225225);


        public MatrixDraw()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

      Angle = 0;
      XlateY = 0;
      xlate.Minimum = -50;
      xlate.Maximum = 50;
      xlate.SmallChange = 1;
      xlate.LargeChange = 5;
      xlate.Value = 0;

      rotate.Minimum = -180;
      rotate.Maximum = 180;
      rotate.SmallChange = 1;
      rotate.LargeChange = 10;
      rotate.Value = 0;

      this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
      this.SetStyle(ControlStyles.DoubleBuffer, true);
      this.SetStyle(ControlStyles.UserPaint, true);
    }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Disposebool disposing )
        {
            ifdisposing )
            {
                if (components != null
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
      this.rotate = new System.Windows.Forms.HScrollBar();
      this.xlate = new System.Windows.Forms.VScrollBar();
      this.SuspendLayout();
      // 
      // rotate
      // 
      this.rotate.Location = new System.Drawing.Point(8240);
      this.rotate.Name = "rotate";
      this.rotate.Size = new System.Drawing.Size(24016);
      this.rotate.TabIndex = 3;
      this.rotate.Scroll += new System.Windows.Forms.ScrollEventHandler(this.rotate_Scroll);
      // 
      // xlate
      // 
      this.xlate.Location = new System.Drawing.Point(26432);
      this.xlate.Name = "xlate";
      this.xlate.Size = new System.Drawing.Size(16200);
      this.xlate.TabIndex = 2;
      this.xlate.Scroll += new System.Windows.Forms.ScrollEventHandler(this.xlate_Scroll);
      // 
      // MatrixDraw
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.rotate,
                                                                  this.xlate});
      this.MaximizeBox = false;
      this.MinimizeBox = false;
      this.Name = "MatrixDraw";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "MatrixDraw";
      this.Load += new System.EventHandler(this.MatrixDraw_Load);
      this.ResumeLayout(false);

    }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new MatrixDraw());
        }

    private void MatrixDraw_Load(object sender, System.EventArgs e)
    {
    }

    protected override void OnPaint(PaintEventArgs e)
    {
      Graphics G  = e.Graphics;

      G.SmoothingMode = SmoothingMode.AntiAlias;

      // Create a graphics path, add a rectangle, set colors
      GraphicsPath Path = new GraphicsPath();
      Path.AddRectangle(new Rectangle(7510010075));
      PointF[] Pts  = Path.PathPoints;
      PathGradientBrush B = new PathGradientBrush(Pts);
      B.CenterColor = Color.Aqua;
      Color[] SColor = {Color.Blue};
      B.SurroundColors = SColor;

      //We will translate the brush!  NOT the rectangle!
      Matrix m = new Matrix();
      m.Translate(0, XlateY, MatrixOrder.Append);
      m.RotateAt(Angle, B.CenterPoint, MatrixOrder.Append);
      B.MultiplyTransform(m, MatrixOrder.Append);
      G.FillRectangle(B, DrawingRect);

      base.OnPaint(e);
      m.Dispose();
      B.Dispose();
      Path.Dispose();
    }

    private void xlate_Scroll(object sender, 
                              System.Windows.Forms.ScrollEventArgs e)
    {
      XlateY = xlate.Value;
      this.Invalidate(DrawingRect);
    }

    private void rotate_Scroll(object sender, 
                               System.Windows.Forms.ScrollEventArgs e)
    {
      Angle = rotate.Value;
      this.Invalidate(DrawingRect);
    }
    }
}


           
       
Related examples in the same category
1.new Matrix(0.707f, 0.707f, -0.707f, 0.707f, 0, 0)
2.Text direction (Matrix Rotate)
3.Matrix DemoMatrix Demo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.