CADability dotNET

This is the older manual approach to get started with CADability. Consider to use the newer and much simpler start with "How to build your first application using CADability".

First Steps of Using CADability

  • To create your first application unsing CADability, you start with an empty Windows.Forms application and copy the following lines to your application. You also can start with the provided "myCADapp" application, which contains the following source code.

    There should be no problem to convert this sourcecode to any other .NET language.

  • You can also modify the menu or provide your own menu. If you only need a display and no interactions, you wont have to use the userinterface objects (e.g. toolbars, controlcenter) at all.


/// Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CADability;
using CADability.UserInterface;

namespace myCADapp
    /// <summary xmlns="">
    /// This is a simple System.Windows.Forms.Form.
    /// </summary>
    public partial class MainForm : Form
        private SingleDocumentFrame sdiFrame; // the hub for CADability
        private ControlCenter controlCenter; // the ControlCenter
        private Splitter propertySplitter; // a simple splitter to resize the ControlCenter
        private ToolBarDockContainer topToolBars; // a container for the top toolbars
        private ToolBarDockContainer leftToolBars; // a container for the left toolbars
        private MoveableToolBar[] allToolbars; // all toolbars in an array

        public MainForm()
            InitializeComponent(); // required and generated by the designer but almost empty

            // 1. create the hub that pulls all the strings together
            sdiFrame = new SingleDocumentFrame();
            // 2. create the necessary controls
            controlCenter = new ControlCenter(sdiFrame);
            propertySplitter = new Splitter();
            topToolBars = new ToolBarDockContainer(sdiFrame);
            leftToolBars = new ToolBarDockContainer(sdiFrame);

            // place the controls in this form
            Controls.AddRange(new Control[] {sdiFrame.DisplayArea,leftToolBars,propertySplitter,

            this.Text = "myCADapp";
            // set the DockStyles. the order is important.
            controlCenter.Dock = System.Windows.Forms.DockStyle.Right;
            propertySplitter.Dock = System.Windows.Forms.DockStyle.Right;
            topToolBars.Dock = System.Windows.Forms.DockStyle.Top;
            leftToolBars.Dock = System.Windows.Forms.DockStyle.Left;
            sdiFrame.DisplayArea.Dock = System.Windows.Forms.DockStyle.Fill;


            // load some standard toolbars
            MoveableToolBar ToolBarFile = MoveableToolBar.CreateStandardToolBar("File", sdiFrame);
            MoveableToolBar ToolBarEdit = MoveableToolBar.CreateStandardToolBar("Edit", sdiFrame);
            MoveableToolBar ToolBarZoom = MoveableToolBar.CreateStandardToolBar("Zoom", sdiFrame);
            MoveableToolBar ToolBarConstruct = MoveableToolBar.CreateStandardToolBar("Construct", sdiFrame);
            MoveableToolBar ToolBarSnap = MoveableToolBar.CreateStandardToolBar("Snap", sdiFrame);
            // create your own toolbar as an example
            MoveableToolBar MyToolBar = MoveableToolBar.CreateCustomToolBar("MyToolBar", sdiFrame,
                new string[] {"MenuId.Object.Move","MenuId.Object.Rotate","MenuId.Object.Scale",
            // coollect all toolbars in an array
            allToolbars = new MoveableToolBar[] { ToolBarFile, ToolBarEdit, ToolBarZoom, ToolBarConstruct, ToolBarSnap, MyToolBar };
            // try to either restore the toolbar positions from the last session or to position them initially
            if (!sdiFrame.RestoreToolbarPosition(new ToolBarDockContainer[] { topToolBars, leftToolBars }, allToolbars))

            // load the standard menu and set it a s the main menu of this form
            this.Menu = MenuResource.LoadMenu("SDI Menu", sdiFrame);

            // display the context sensitive help control in the control center
            controlCenter.ShowHelpControl = true; 

            // register an event to handle menu commands
            sdiFrame.ProcessCommandEvent += new ProcessCommandDelegate(OnProcessCommand);
            // register an event to handle the display of the filename in the title bar
            sdiFrame.FileNameChangedEvent += new SingleDocumentFrame.FileNameChangedDelegate(OnFileNameChanged);

            // start with an empty project
            (sdiFrame as ICommandHandler).OnCommand("MenuId.File.New"); 


        protected override void Dispose(bool disposing)
            // save the toolbar position before this form is closed
            sdiFrame.SaveToolbarPosition(new ToolBarDockContainer[] { topToolBars, leftToolBars }, allToolbars);
        private void OnFileNameChanged(string NewProjectName)
            // displays the file name of the current project in the title bar.
            this.Text = NewProjectName + " (myCADapp)";
        private void OnProcessCommand(string MenuId, ref bool Processed)
            // handle the menu "App.Exit", the only standerd menu item that isnt handle by CADability itself
            if (MenuId == "MenuId.App.Exit")
                Processed = true;
        protected override void OnClosing(CancelEventArgs e)
            // ask the sdi frame to prompt the user for with file save dialog if the modifed flag is set