Draw closed curve : 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
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » 2D Graphics » CurveScreenshots 
Draw closed curve
Draw closed curve


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{
   private Point[] thePoints;
   private int counter;

   public Form1() {
      Console.WriteLine("click on the form to draw closed curve.");
    
    
      InitializeComponent();
      thePoints = new Point[1000];
      for (int i=0;i<thePoints.Length; i++)
         thePoints[inew Point(0,0);
      counter =0;
   }
   protected override void OnPaint (PaintEventArgs e) {
      if (counter==0
         return;

      Pen redPen   = new Pen(Color.Red, 3);
      Pen greenPen = new Pen(Color.Red, 4);
      Point[] curvePoints = new Point[counter];
      
      for (int i=0; i<curvePoints.Length;i++)
      {
         curvePoints[inew Point(0,0);
         curvePoints[i].X = thePoints[i].X;
         curvePoints[i].Y = thePoints[i].Y;
      }
        
      e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
      e.Graphics.DrawClosedCurve(greenPen, curvePoints);
   }

   private void InitializeComponent() {
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292273);
      this.Name = "Form1";
      this.Text = "Form1";
      this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
   }

   static void Main() {
      Application.Run(new Form1());
   }

   private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
      thePoints[counter].X = e.X;
      thePoints[counter].Y = e.Y;
      Label l = new Label();
      this.SuspendLayout();

      counter++;
      if (counter>4)
        this.Refresh();
  }
}
           
       
Related examples in the same category
1. Sine Curve
2. Ellipse with DrawLines
3. Spiral
4. Bezier (Mouse Defines Control Points)
5. Click on the form to draw curveClick on the form to draw curve
w___w___w_._ja__va_2s.___com_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.