Profile Picture

Custom command with custom shape tool

Posted By usyber 10 Years Ago
Author
Message
usyber
Problem Posted 10 Years Ago
View Quick Profile
Junior Member

Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 10, Visits: 106
Hi,

I would like to add a custom commad to the 'Tools' toolbar which enables the user to draw a custom shape. The custom shape tool works well but the custom command isn't shown. How can I do this?

public class CreateChannelCommand : NDiagramCheckButtonCommand
{
#region Member

private NCustomImageList mimageList;

#endregion

public CreateChannelCommand(): base((int) DiagramCommandRange.Tools, (int) 88888, "Channel create tool", "Channel tool")
{
try
{
mimageList = new NCustomImageList(Image.FromFile(@"C:\Temp\Prozessbildeditor\Nevron\Test\WindowsFormsApplication2\icon\gear_add.bmp"), new NSize(16, 16));
}
catch (Exception e)
{
}
}

public override string Text
{
get { return "Hello channel command"; }
}

public override bool Enabled
{
get
{
if (Commander == null || Commander.View == null)
return false;

return true;
}
}

public override bool Checked
{
get
{
if (Commander == null)
return false;

NDrawingView view = Commander.View;
if (view == null)
return false;

return view.Controller.Tools.IsToolEnabled("CreateChannelCommand");
}
}

public override void Execute()
{
if (Commander == null)
return;

NDrawingView view = Commander.View;
if (view == null)
return;

view.Controller.Tools.SingleEnableTool("CreateChannelCommand");
}

public override string TooltipText
{
get
{
return "Chhaannel";
}
set
{
base.TooltipText = value;
}
}

public override bool GetImageInfo(out NCustomImageList imageList, out int imageIndex)
{
imageList = this.mimageList;
imageIndex = 0;
return true;
// return base.GetImageInfo(out imageList, out imageIndex);
}




}//Within my Form1_Load
var cmd = new CreateChannelCommand();
nDiagramCommandBarsManager1.Commander.Commands.Add(cmd);
nDiagramCommandBarsManager1.Recreate();

NCreateShapeTool createChannelShapeTool = new NCreateShapeTool();
createChannelShapeTool.Name = "CreateChannelTool";
createChannelShapeTool.Shape = new MyChannelShape();

nDrawingView1.Controller.Tools.Add(createChannelShapeTool);
nDrawingView1.Controller.Tools.EnableTools(new[] { "CreateChannelTool" });


best regards,
Uli

Nevron Support
Posted 10 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746
Hi Uli,

First you will need to change the value of the second parameter in the CreateChanelCommand constructor from (int)8888 to (int)DiagramCommand.LastCommandId + 1

You will also need to create your custom toolbars builder class similar to the following:


public class MyNDiagramToolBarsBuilder : NDiagramToolbarsBuilder
{
    public override NDockingToolbar[] BuildToolbars()
    {
        ArrayList toolbars = new ArrayList(base.BuildToolbars());
        int commandId = (int)DiagramCommand.LastCommandId + 1;
        NCommand command = CreateCommand(commandId, false);
        for (int i = 0; i < toolbars.Count; i++)
        {
            NToolbar toolbar = toolbars[i] as NToolbar;
            if(toolbars == null)
            {
                continue;
            }
            if (toolbar.Text == "Tools")
            {
                toolbar.Commands.Add(command);
            }
        }
        return (NDockingToolbar[])toolbars.ToArray(typeof(NDockingToolbar));
    }

    public override void Reset()
    {
        base.Reset();

        customCommandIds = new ArrayList();
        customCommandIds.Add((int)DiagramCommand.LastCommandId + 1);
    }

    private ArrayList customCommandIds;
}


Then you will need to set an instance of the class above to NDiagramCommandBarsManager.ToolbarsBuilder property.

I hope this helps.



Best Regards,
Nevron Support Team



usyber
Posted 10 Years Ago
View Quick Profile
Junior Member

Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)Junior Member (16 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 10, Visits: 106
Dear Nevron support team,

works like a charm. Thank you for your quick response.

best regards,
Uli




Similar Topics


Reading This Topic