using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormsBezier
{
public partial class Form1 : Form
{
protected Point[] apt = new Point[4];
public Form1()
{
InitializeComponent();
Text = "Bezier (Mouse Defines Control Points)";
BackColor = SystemColors.Window;
ForeColor = SystemColors.WindowText;
ResizeRedraw = true;
OnResize(EventArgs.Empty);
}
private void Form1_Resize(object sender, EventArgs e)
{
int cx = ClientSize.Width;
int cy = ClientSize.Height;
apt[0] = new Point(cx / 4, cy / 2);
apt[1] = new Point(cx / 2, cy / 4);
apt[2] = new Point(cx / 2, 3 * cy / 4);
apt[3] = new Point(3 * cx / 4, cy / 2);
}
private void Form1_MouseDown(object sender, 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);
}
private void Form1_Paint(object sender, 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]);
}
private void Form1_MouseMove(object sender, MouseEventArgs mea)
{
if (mea.Button == MouseButtons.Left)
{
apt[1] = new Point(mea.X, mea.Y);
Invalidate();
}
else if (mea.Button == MouseButtons.Right)
{
apt[2] = new Point(mea.X, mea.Y);
Invalidate();
}
}
}
}