algates0027 0 Newbie Poster
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<GraphicsPath> pathes = new List<GraphicsPath>();

        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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.