Using Layout toolbar in custom windows forms designer

Hi,

I am building a custom windows forms designer and I would like to enable the "Layout" toolbar for it so that I can use Align commands (and also TabOrder command). VS does ask the designer if designer supports these commands, but I do not know what to do once the user activates the command.

My designer uses existing DesignSurface class for design. Does the existing DesignSurface support Align and TabOrder commands out of the box If so, how can I turn them on

Thanks.



Answer this question

Using Layout toolbar in custom windows forms designer

  • ravensensei

    Hi everybody,

    I have found the solution. The solution is to use System.Windows.Forms.Design.TabOrder class. This class is internal so you must use reflection in order to instantiate it. Here is a sample on how to do it:

    IDesignerHost _host =....;

    /// <summary>
    /// Enables/Disables visual TabOrder on the view.
    /// </summary>
    internal override void DoVisualTabOrder() {
    Assembly designAssembly = Assembly.Load("System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
    Type tabOrderType = designAssembly.GetType("System.Windows.Forms.Design.TabOrder");
    if (_tabOrder == null) {
    _tabOrder =
    Activator.CreateInstance(tabOrderType, new object[] { _host });
    } else {
    DisposeTabOrder();
    }
    }

    private object _tabOrder = null;

    /// <summary>
    /// Disposes the tab order.
    /// </summary>
    private void DisposeTabOrder() {
    if (_tabOrder == null)
    return;
    Assembly designAssembly = Assembly.Load("System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
    Type tabOrderType = designAssembly.GetType("System.Windows.Forms.Design.TabOrder");
    tabOrderType.InvokeMember("Dispose", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, _tabOrder, new object[] { true });
    _tabOrder = null;
    }


  • dalieu

    Hi, i want to extend the XAML editor, to make something like this, but only available for my own controls I think it should be simmilar to yours... could you point me how to achieve this

    Thanks

  • Using Layout toolbar in custom windows forms designer