Table of Contents

Property DesignerCommands

Namespace
Alternet.FormDesigner.WinForms
Assembly
Alternet.FormDesigner.v9.dll

DesignerCommands

Represents a collection of standard designer commands like selecting, copying, pasting, moving and resizing controls.

[Browsable(false)]
public IFormDesignerCommands DesignerCommands { get; }

Property Value

IFormDesignerCommands

Examples

Here is how to use a DesignerCommands in the C# code:

using System.Windows.Forms;

using Alternet.FormDesigner.WinForms;

public partial class Form1 : Form
{
    private void Form1_Load(object sender, EventArgs e)
    {
        var formDesigner = new FormDesignerControl();
        formDesigner.AutoSaveToSource = false;
        formDesigner.Dock = System.Windows.Forms.DockStyle.Fill;
        formDesigner.Parent = this;

        var command = formDesigner.CommandKeyBindings.Find(x => x.Do == formDesigner.DesignerCommands.Undo);
        if (command != null)
        {
            formDesigner.CommandKeyBindings.Remove(command);
            formDesigner.CommandKeyBindings.Add(new CommandKeyBinding(Keys.Z, Keys.Alt, formDesigner.DesignerCommands.Undo, () => formDesigner.DesignerCommands.CanUndo));
        }

        var extendCommand = new CommandKeyBinding(Keys.K, Keys.Control | Keys.Shift, CustomAction, () => true);
        designer.CommandKeyBindings.Add(extendCommand);
    }

    private void CustomAction()
    {
        MessageBox.Show("Custom command");
    }
}

Here is how to use a DesignerCommands in the Visual Basic code:

Imports System.Windows.Forms

Imports Alternet.FormDesigner.WinForms

Partial Public Class Form1
    Inherits Form

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim formDesigner = New FormDesignerControl()
        formDesigner.AutoSaveToSource = False
        formDesigner.Dock = System.Windows.Forms.DockStyle.Fill
        formDesigner.Parent = Me
        Dim command = formDesigner.CommandKeyBindings.Find(Function(x) x.KeyCode = Keys.Z)
        If command IsNot Nothing Then
            formDesigner.CommandKeyBindings.Remove(command)
            formDesigner.CommandKeyBindings.Add(New CommandKeyBinding(Keys.Z, Keys.Alt, AddressOf formDesigner.DesignerCommands.Undo, Function() formDesigner.DesignerCommands.CanUndo))
        End If

        Dim extendCommand = New CommandKeyBinding(Keys.K, Keys.Control Or Keys.Shift, AddressOf CustomAction, Function() True)
        designer.CommandKeyBindings.Add(extendCommand)
    End Sub

    Private Sub CustomAction()
        MessageBox.Show("Custom command")
    End Sub
End Class

Remarks

Any standard Form Designer's command can be called directly from code or by pressing a hot key combination. You can programmatically change this combination.