954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

cut operation +C#

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

Bitmap = new Bitmap(SystemInformation.WorkingArea.Width, SystemInformation.WorkingArea.Height); //editted

grfx = Graphics.FromImage(Bitmap); //Editted


}

private void Form1_Load(object sender, EventArgs e)

{

GraphicsPath path = new GraphicsPath();

path.AddRectangle(new Rectangle(10, 10, 100, 50));

this.pathes.Add(path);

path = new GraphicsPath();

path.AddPolygon(new Point[] {

new Point(50, 150), new Point(100, 100), new Point(150, 150) });

this.pathes.Add(path);

path = new GraphicsPath();

path.AddEllipse(new Rectangle(160, 70, 100, 100));

this.pathes.Add(path);

this.Paint += new PaintEventHandler(Form1_Paint);

this.MouseClick += new MouseEventHandler(Form1_MouseClick);

//menu

this.menu.Items.Add("Copy");

this.menu.Items.Add("Cut");

this.menu.Items.Add("Paste");

this.menu.Items[2].Enabled = false;

this.menu.ItemClicked += new ToolStripItemClickedEventHandler(menu_ItemClicked);

}

List pathes = new List();

GraphicsPath selectedPath = null;

ContextMenuStrip menu = new ContextMenuStrip();

void menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)

{

switch (e.ClickedItem.Text)

{

case "Copy":

if (this.selectedPath != null)

{

Clipboard.SetDataObject(new GraphicsPathObject(this.selectedPath));

this.menu.Items[2].Enabled = true;

}

break;

case "Cut":

if (this.selectedPath != null)

{

GraphicsPathObject pathObject =

new GraphicsPathObject(this.selectedPath);

Clipboard.SetDataObject(pathObject);

this.pathes.Remove(this.selectedPath);

this.selectedPath = null;

this.Invalidate();

this.menu.Items[2].Enabled = true;

}

break;

case "Paste":

{

IDataObject data = Clipboard.GetDataObject();

GraphicsPathObject pathObject = data.GetData(

Clipboard.GetDataObject().GetFormats()[0])

as GraphicsPathObject;

GraphicsPath path = new GraphicsPath(pathObject.Points,

pathObject.Bytes);

this.pathes.Add(path);

this.Invalidate();

this.menu.Items[2].Enabled = false;

}

break;

}

}

protected override void OnPaint(PaintEventArgs pe)

{
Graphics g = pe.Graphics;

g.DrawImage(Bitmap, this.AutoScrollPosition.X, this.AutoScrollPosition.Y,Bitmap.Width,Bitmap.Height); //editted
base.OnPaint(pe);
}

My doubt is how can i remove selected path while cut operation using this Bitmap


Regards,

ALGATES..

algates0027
Newbie Poster
2 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You