Bezier (Mouse Defines Control Points) : Curve « 2D Graphics « C# / C Sharp

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. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
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
ww___w.__j__a___v__a2___s__.___c___o_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.