Deshacer operación en cuadro de imagen para deshacer rectángulos dibujados en C#.net

In my project there is picturebox,user will first select image by clicking on View image button.This image will be as per the image name in textbox in front of view image button.User will now click on picturebox and points are drwan in shape of small rectangles.After selecting points user will click on draw curve button and smooth curve is drawn as i have used Drawclosedcurve method of graphics class. My question is;suppose user mistakely clicks a point and he want to UNDO that point,so what will be solution??

preguntado el 24 de agosto de 12 a las 08:08

1 Respuestas

¿Ha pensado en utilizar un stack to store your actions, for example make a class to store your actions and then enumerate your action types:

enum ActionType
{
    DrawPoint = 1,
    DrawCurve = 2
}

public class Action
{
    public int X { get; set; }
    public int Y { get; set; }
    public ActionType Action { get; set; }
}

Then whenever the user clicks to make a point you create an Action from this and push it onto your Stack al igual que:

Stack eventStack = new Stack<Action>();

// capture event either clicking on PictureBox or clicking on Curve button
// and convert to action

Action action = new Action() {
    X = xPosOnPictureBox,
    Y = yPosOnPictureBox,
    ActionType = ActionType.DrawPoint
};

eventStack.push(action);

You can then proceed to render your picture box based on your stack. When you want to undo simply pop the most recent action off the stack and then redraw your PictureBox from the events left on the stack.

protected void btnUndo_Click(object sender, EventArgs e)
{
    var action = eventStack.pop();

    // ignore action as we just want to remove it

    // now redraw your PictureBox with what's left in the Stack
}

This code is obviously not tested and will need moulding into your structure, but it should be enough to go off.

Respondido 24 ago 12, 09:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.