Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

Cancelling an action if a line is not docked correctly.

Last post 09-13-2007 10:17 PM by James Westgate. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 09-13-2007 10:17 PM

    Cancelling an action if a line is not docked correctly.

    1. You may want to expand the logic that determines if the line can dock to the shape it is over. You can do this by overriding the Runtime.CanDock method and providing your own implementation. In the example below we prevent docking to any element with an Opacity less than 100%:

    public class MyRuntime: Runtime
    {
       
    public override bool CanDock(Diagram.MouseElements
    mouseElements)
        {
           
    if (mouseElements.MouseMoveElement != null && mouseElements.MouseMoveElement.Opacity < 100) return false
    ;
           
    return base
    .CanDock(mouseElements);
        }
    }

    2. Then make sure you set the Model.Runtime property to an instance of your runtime class.

    model1.Runtime = new MyRuntime();

    3. You need to cancel an action if it is invalid. This can be done simply by clearing the elements involved in the action before it is updated. To do this create a Model subclass and override UpdateElements, clearing the Actions collection.

    public class MyModel: Model
    {
        protected override void
    UpdateElements()
        {
            //Clear the list of actions so that they are not updated.
            if (CurrentMouseElements.MouseStartOrigin != null
    && !Runtime.CanDock(CurrentMouseElements)) RenderDesign.Actions.Clear();

            //Call the base implementation
            base
    .UpdateElements();
        }
    }

    (Please see the Advanced section of the help file for more information regarding subclassing the Model control)

    • 86.150.193.191
Page 1 of 1 (1 items)