Draw closed curve : 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 
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.