cut operation +C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alarock
    New Member
    • Jan 2008
    • 14

    cut operation +C#

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeCompo nent();

    Bitmap = new Bitmap(SystemIn formation.Worki ngArea.Width, SystemInformati on.WorkingArea. Height); //editted

    grfx = Graphics.FromIm age(Bitmap); //Editted


    }



    private void Form1_Load(obje ct sender, EventArgs e)

    {

    GraphicsPath path = new GraphicsPath();

    path.AddRectang le(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 PaintEventHandl er(Form1_Paint) ;

    this.MouseClick += new MouseEventHandl er(Form1_MouseC lick);



    //menu

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

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

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

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

    this.menu.ItemC licked += new ToolStripItemCl ickedEventHandl er(menu_ItemCli cked);

    }



    List<GraphicsPa th> pathes = new List<GraphicsPa th>();

    GraphicsPath selectedPath = null;

    ContextMenuStri p menu = new ContextMenuStri p();



    void menu_ItemClicke d(object sender, ToolStripItemCl ickedEventArgs e)

    {

    switch (e.ClickedItem. Text)

    {

    case "Copy":

    if (this.selectedP ath != null)

    {

    Clipboard.SetDa taObject(new GraphicsPathObj ect(this.select edPath));

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

    }

    break;

    case "Cut":

    if (this.selectedP ath != null)

    {

    GraphicsPathObj ect pathObject =

    new GraphicsPathObj ect(this.select edPath);

    Clipboard.SetDa taObject(pathOb ject);

    this.pathes.Rem ove(this.select edPath);

    this.selectedPa th = null;

    this.Invalidate ();

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

    }

    break;

    case "Paste":

    {

    IDataObject data = Clipboard.GetDa taObject();



    GraphicsPathObj ect pathObject = data.GetData(

    Clipboard.GetDa taObject().GetF ormats()[0])

    as GraphicsPathObj ect;



    GraphicsPath path = new GraphicsPath(pa thObject.Points ,

    pathObject.Byte s);



    this.pathes.Add (path);

    this.Invalidate ();

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

    }

    break;

    }

    }

    protected override void OnPaint(PaintEv entArgs pe)

    {
    Graphics g = pe.Graphics;

    g.DrawImage(Bit map, this.AutoScroll Position.X, this.AutoScroll Position.Y,Bitm ap.Width,Bitmap .Height); //editted
    base.OnPaint(pe );
    }





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


    Regards,

    ALGATES..
Working...