Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Can't see added controls after undo/redo
 

Can't see added controls after undo/redo

My implementation of UndoEngine seems to work for most actions; movement, resize, deletion, property edits etc. However, when I add components to my DesignSurface with IDesignerHost.CreateComponent I can undo but cannot redo.

Stepping through I can see that undo removes the component from the IDesignerHost.Components collection and redo puts it back but it's not re-appearing on the design surface.
What's happening to it!?

Edit: I've realised that the final step of adding my component is to set its parent as the IDesignerHost.RootComponent. This was not being done via PropertyDescriptor's and so I was missing this change in my UndoEngine. I've amended that but now It seems that Control.Parent is not restored by undo/redo. Should I be tracking the change to RootComponent.Controls collection instead?

Edit 2: It now seems to work, a bit. I've explicitly forced the change to the Parent property made via its PropertyDescriptor.SetValue function to be recorded as part of my DesignerTransaction by raising the OnComponentChanging and OnComponentChanged events myself. I can undo and redo the addition of a control but it gets a bit messed up if you do this;

1. Add a control, undo becomes available.
2. Undo the added control, control is removed, redo becomes available.
3. Add a different control, new control is added.
4. Redo the first control add.

The above sequence seems to replace the second control with the recreated first control and that second control appears lost.
A.J.Lawson  Wednesday, July 16, 2008 3:36 PM
Hi Lawson,

This is rajesh from india I am also implementing the Undo/Redo control to our designer. I am also getting the same problem as you and inaddition to that i am not able to perform undo action after performing the delete and cut. If you able to perform undo on delete and cut please give me your
UndoEnine class implementation code please send me as early as possible because i need it very much.

and my UndoEngine class implementation is like this


public class UndoEngineService : UndoEngine

{

List<UndoEngine.UndoUnit> undoUnitList = new List<UndoUnit>();

// points to the command that should be executed for Redo

int currentPos = 0;

public UndoEngineService(IServiceProvider provider) : base(provider)

{

}

public void DoUndo()

{

if (currentPos > 1)

{

UndoEngine.UndoUnit undoUnit = undoUnitList[currentPos-1];

undoUnit.Undo();

currentPos--;

}

UpdateUndoRedoMenuCommandsStatus();

}

public void DoRedo()

{

if (currentPos < undoUnitList.Count)

{

UndoEngine.UndoUnit undoUnit = undoUnitList[currentPos];

undoUnit.Undo();

currentPos++;

}

UpdateUndoRedoMenuCommandsStatus();

}

private void UpdateUndoRedoMenuCommandsStatus()

{

// this components maybe cached.

MenuCommandService menuCommandService = GetService(typeof(MenuCommandService)) as MenuCommandService;

MenuCommand undoMenuCommand = menuCommandService.FindCommand(StandardCommands.Undo);

MenuCommand redoMenuCommand = menuCommandService.FindCommand(StandardCommands.Redo);

if (undoMenuCommand != null)

undoMenuCommand.Enabled = currentPos > 0;

if (redoMenuCommand != null)

redoMenuCommand.Enabled = currentPos < this.undoUnitList.Count;

}

protected override void AddUndoUnit(UndoEngine.UndoUnit unit)

{

undoUnitList.RemoveRange(currentPos, undoUnitList.Count - currentPos);

undoUnitList.Add(unit);

currentPos = undoUnitList.Count;

}

public static int myNumber = 0;

protected override UndoEngine.UndoUnit CreateUndoUnit(string name, bool primary)

{

return base.CreateUndoUnit(name, primary);

}

protected override void DiscardUndoUnit(UndoEngine.UndoUnit unit)

{

undoUnitList.Remove(unit);

base.DiscardUndoUnit(unit);

}

protected override void OnUndoing(EventArgs e)

{

base.OnUndoing(e);

}

protected override void OnUndone(EventArgs e)

{

base.OnUndone(e);

}





please send me your UndoEngine class implementation to my gmail id rajesh1533@gmail.com
plese send me.




Thanks and Regards
Rajesh

CSHARP by SHARP  Tuesday, February 03, 2009 7:04 AM

You can use google to search for other answers

Custom Search

More Threads

• IDesignerHost Blocks Mouse Events
• BackgroundImageLayout missing in MdiClient control
• class Constructor help - passing arguements
• Read outlook email and then save data into SQL server
• 2 WinForm bugs
• Alpha-Blending a Control at Design Time
• Remove white bottom border on a Toolstrip
• Making a .net Grid
• Common Langauge Runtime Debugging Services
• Accessing GroupName information from GetPropertyValues and SetPropertyValues in the custom SettingsProvider