Bezier (Mouse Defines Control Points) : Curve « 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 » CurveScreenshots 
Bezier (Mouse Defines Control Points)
 
using System;
using System.Drawing;
using System.Windows.Forms;
   
class Bezier: Form
{
     protected Point[] apt = new Point[4];
   
     public static void Main()
     {
          Application.Run(new Bezier());
     }
     public Bezier()
     {
          ResizeRedraw = true;
   
          OnResize(EventArgs.Empty);
     }
     protected override void OnResize(EventArgs ea)
     {
          base.OnResize(ea);
   
          int cx = ClientSize.Width;
          int cy = ClientSize.Height;
   
          apt[0new Point(    cx / 4,     cy / 2);
          apt[1new Point(    cx / 2,     cy / 4);
          apt[2new Point(    cx / 2* cy / 4);
          apt[3new Point(* cx / 4,     cy / 2);
     }
     protected override void OnMouseDown(MouseEventArgs mea)
     {
          Point pt;
   
          if (mea.Button == MouseButtons.Left)
               pt = apt[1];
   
          else if (mea.Button == MouseButtons.Right)
               pt = apt[2];
   
          else
               return;
   
          Cursor.Position = PointToScreen(pt);
     }
     protected override void OnMouseMove(MouseEventArgs mea)
     {
          if (mea.Button == MouseButtons.Left)
          {
               apt[1new Point(mea.X, mea.Y);
               Invalidate();
          }
          else if (mea.Button == MouseButtons.Right)
          {
               apt[2new Point(mea.X, mea.Y);
               Invalidate();
          }
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics grfx = pea.Graphics;
   
          grfx.DrawBeziers(new Pen(ForeColor), apt);
   
          Pen pen = new Pen(Color.FromArgb(0x80, ForeColor));
   
          grfx.DrawLine(pen, apt[0], apt[1]);
          grfx.DrawLine(pen, apt[2], apt[3]);
     }
}

 
Related examples in the same category
1.Sine Curve
2.Ellipse with DrawLines
3.Spiral
4.Draw closed curveDraw closed curve
5.Click on the form to draw curveClick on the form to draw curve
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.