Table of Contents

Property CommandKeyBindings

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

CommandKeyBindings

Represents a list of CommandKeyBinding accepted by this FormDesignerControl.

[Browsable(false)]
public List<CommandKeyBinding> CommandKeyBindings { get; }

Property Value

List<CommandKeyBinding>

Examples

Here is how to use a CommandKeyBindings 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 CommandKeyBindings 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

You can extend this list of the standard designer commands or change any key combination for an existing command.