Group: Forum Members
Last Active: 12 Years Ago
Posts: 71,
Visits: 1
|
Refer to the following knowledge base below. I couldn't find a way to cancel the node inserting. For instance, user drag a shape from the library to the drawing area, then a messagebox comes up. If users click yes, the shape is added to the area then if user clicks cancel the shape is not inserted to the drawing area. So how can I do that? The node removing works fine, but not the inserting.
Question:
I have created a diagram that uses a library browser. I can drag and drop several object from the library to the document. The task that I need is for an event to fire on the creation of a new shape, and also an event when an already created shape is altered/deleted. I am having trouble finding a way to hook into these events. These are object that will be created during the run-time of the program. I saw examples for adding changed value events for programmatically created object, but I need for these event handlers to apply to all object created from the library browser. Any information on this would be greatly appreciated.
Answer:
The NodeInserted and NoderRemoved events of the document event sink service will be fired whenever a node has been inserted or removed from the document regardless of the way in which this was done. You can subscribe for this events with the following code:
document.EventSinkService.NodeInserted += new ChildNodeEventHandler(OnNodeInserted); document.EventSinkService.NodeRemoved += new ChildNodeEventHandler(OnNodeRemoved);
private void OnNodeInserted(NChildNodeEventArgs args) { if (args.Child is NShape) { // do something when a shape is added } }
|