I managed to dig this example up. It's not exactly what you need but it
shows how to hit-test and move those little grab rectangles. I'm sure you
could adapt it somehow.
Code after my signature...
--
Bob Powell [MVP]
C#, System.Drawing
The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
Read my Blog at
http://bobpowelldotnet.blogspot.com
-----------------------------------------------------------
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace warped.cs
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private GraphicsPath pth=new GraphicsPath(FillMode.Alternate);
PointF[] destPoints = new PointF[4];
private bool inPoint=false;
private int pointIndex=0;
private System.Windows.Forms.StatusBar statusBar1;
private bool mouseDown;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel2 = new System.Windows.Forms.Panel();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 263);
this.panel1.TabIndex = 0;
this.panel1.Paint += new
System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(200, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 263);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.White;
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(203, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(309, 263);
this.panel2.TabIndex = 2;
this.panel2.MouseUp += new
System.Windows.Forms.MouseEventHandler(this.panel2_MouseUp);
this.panel2.Paint += new
System.Windows.Forms.PaintEventHandler(this.panel2_Paint);
this.panel2.MouseMove += new
System.Windows.Forms.MouseEventHandler(this.panel2_MouseMove);
this.panel2.MouseLeave += new
System.EventHandler(this.panel2_MouseLeave);
this.panel2.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.panel2_MouseDown);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 263);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(512, 22);
this.statusBar1.TabIndex = 3;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(512, 285);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel2,
this.splitter1,
this.panel1,
this.statusBar1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void panel1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Pen p=new Pen(Color.Black,-1);
e.Graphics.DrawPath(p,pth);
p.Dispose();
}
private void Form1_Load(object sender, System.EventArgs e)
{
pth.AddRectangle(new Rectangle(20,80,100,200));
pth.AddEllipse(100,150,120,120);
pth.AddString("You can warp text and graphics...",new
FontFamily("Arial"),(int)FontStyle.Bold,20,new
Rectangle(10,0,300,300),StringFormat.GenericTypographic);
destPoints[0]=new PointF(20,20);
destPoints[1]=new PointF(240,20);
destPoints[2]=new PointF(20,290);
destPoints[3]=new PointF(240,290);
}
private void panel2_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
GraphicsPath warppath =new GraphicsPath(pth.PathPoints,pth.PathTypes);
warppath.Warp(destPoints,pth.GetBounds(),new
Matrix(),WarpMode.Perspective,0);
Pen p=new Pen(Color.Navy,-1);
e.Graphics.DrawPath(p,warppath);
warppath.Dispose();
p.Color=Color.Black;
SolidBrush sb=new SolidBrush(Color.LightGray);
foreach(PointF pf in destPoints)
{
Rectangle r=new Rectangle((int)pf.X-2,(int)pf.Y-2,4,4);
e.Graphics.FillRectangle(sb,r);
e.Graphics.DrawRectangle(p,r);
}
p.Dispose();
}
private void panel2_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
this.statusBar1.Text=string.Format("{0},{1}",e.X,e.Y);
if(!mouseDown)
{
this.Cursor=Cursors.Arrow;
int n=0;
inPoint=false;
foreach(PointF pf in destPoints)
{
if((e.X>pf.X-2 & e.X<pf.X+2) & (e.Y>pf.Y-2 & e.Y<pf.Y+2))
{
this.Cursor=Cursors.SizeAll;
inPoint=true;
pointIndex=n;
break;
}
n++;
}
}
else
{
if(inPoint)
{
destPoints[pointIndex]=new PointF(e.X,e.Y);
this.panel2.Invalidate();
}
}
}
private void panel2_MouseLeave(object sender, System.EventArgs e)
{
Cursor=Cursors.Arrow;
}
private void panel2_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
mouseDown=true;
}
private void panel2_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
mouseDown=false;
}
}
}
-----------------------------------------------------------