Table of Contents

Class FormDesignerControl

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

Represents a control supports all standard form editing operations with controls.

[ToolboxBitmap(typeof(FormDesignerControl), "Images.FormDesignerControl.Icon.bmp")]
public class FormDesignerControl : Control, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable, IFormDesignerControl, ITypeDiscoveryService
Inheritance
FormDesignerControl
Implements

Examples

Here is how to declare a FormDesignerControl and handle its events from the C# code:

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

    private void Designer_ComponentAdded(object sender, ComponentEventArgs e)
    {
        System.Windows.Forms.MessageBox.Show(e.Component.ToString());
    }
}

Here is how to declare a FormDesignerControl and handle its events from the Visual Basic code:

Partial Public Class Form1
    Inherits Form

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim formDesigner = New Alternet.FormDesigner.WinForms.FormDesignerControl()
        formDesigner.AutoSaveToSource = False
        formDesigner.Dock = System.Windows.Forms.DockStyle.Fill
        formDesigner.Parent = Me
        AddHandler designer.ComponentAdded, AddressOf Designer_ComponentAdded
    End Sub

    Private Sub Designer_ComponentAdded(ByVal sender As Object, ByVal e As ComponentEventArgs)
        System.Windows.Forms.MessageBox.Show(e.Component.ToString())
    End Sub
End Class

Remarks

FormDesignerControl control is based on .NET Framework FormDesigner services, which are implemented in System.ComponentModel.Design namespace and included in .NET framework. It allows AlterNET's FormDesignerControl to look and feel very similar to Visual Studio's WinForms Form Designer.

Form Designer supports all common editing operations, such as dragging, selecting, and deleting components and controls; changing their size and z-order; aligning them horizontally or vertically, and copying and pasting controls. Like Visual Studio Form Designer, it serializes its content into C#/VisualBasic code, TypeScript/JavaScript, and Python.

Here are some of the essential features provided by the FormDesigner:

  • Placing controls on the design surface and arranging them.
  • Save/load forms being designed.
  • Write event handlers code and run the designed form.

The DesignerCommands property provides an interface to Form Designer commands, such as Copy/Paste, Undo/Redo, Aligning and Arranging controls, etc.

The SelectedComponents property contains a list of selected components or controls.

Set ToolboxControl property to specify the toolbox control associated with the designer.

Note that FormDesignerControl is compatible with .NET Framework 4.5.2 + and .NET 6.0+

Constructors

FormDesignerControl()

Initializes a new instance of the FormDesignerControl class with default settings.

Properties

AutoAddComponentAssemblyReferences

Gets or sets a boolean value indicating whether designer should automatically try to add assembly references after a control is added.

AutoSaveToSource

Gets or sets a boolean value indicating whether designer should automatically translate changes to the source upon every change.

CommandKeyBindings

Represents a list of CommandKeyBinding accepted by this FormDesignerControl.

DesignerCommands

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

DesignerHost

Provides an interface for managing designer transactions and components.

ImportedNamespaces

In case of Visual Basic, gets collection of globally available namespaces.

IsBeingLoaded

Gets a boolean value indicating that designer is currently being loaded. This property can be used to prevent updating the designer's content before it has fully loaded.

IsModified

Represents a value indicates whether designer content has been modified since last save.

IsSmartDiffCodeSerializationRequired

Gets or sets method used to identify whether FormDesignerControl content should be saved only by taking into account code difference.

Options

Gets designer options like snap settings, grid size etc.

PrimarySelection

Gets first selected component or control. When multiple components are selected in the designer's surface, one of the objects is the primary selected object. Some operations behave differently depending on which selected component is the primary selected object.

ReferencedAssemblies

Gets collection of assemblies where the controls and components used on the form being designed are declared.

SelectedComponents

Contains list of selected components or controls.

ServiceContainer

Represents a container for designer-related services. A service container is, by definition, a service provider. In addition to providing services, it also provides a mechanism for adding and removing services. To obtain a service, call the GetService method. Designer can add or remove services through the IDesignerHost interface.

Source

Gets or sets FormDesigner Source.

ToolboxControl

Gets or sets toolbox control associated with the designer.

UserData

Gets or sets user-specific data associated with this Form Designer. A common use for the UserData property is to store data that is closely associated with the designer.

Methods

CreateContext(IFormDesignerDataSource)
CreateDefaultKeyBindings()
CreateDesignerCommands()
DiscoverKnownTypes(Type)

Return discovered descendand types for the base type

Dispose(bool)

Releases the unmanaged resources used by the Control and its child controls and optionally releases the managed resources.

GetLocalizationLanguage()

Gets current culture information

HandleKeyboardShortcuts(Keys, Keys)
RaiseComponentChanged(object)

Raises ComponentChanged event handler

Reload()

Reloads form to be designed from the source.

Save()

Serializes designer to C# or Visual Basic file.

SetLocalizationLanguage(CultureInfo)

Sets current culture information

ShowPropertiesWindow(object, EventArgs)

Raises ShowPropertiesRequested event

TryAddComponentAssemblyReferences(IComponent)
TryFindCommandKeyBinding(Keys, Keys)
ViewCode(object, EventArgs)

Raises ViewCodeRequested event

Events

CommandStateChanged

Occurs when state of designer commands changes (for example when undo stack becomes available).

CompilerErrorClick

Occurs when a user clicks on compiler error on Form Designer surface.

ComponentAdded

Occurs when some component was added on the designer surface.

ComponentAdding

Occurs when some component is being added on the designer surface.

ComponentChanged

Occurs when some component was changed on the designer surface.

ComponentRemoved

Occurs when some component was removed from the designer surface.

DesignSurfaceKeyDown

Occurs when user presses a key when design surface is focused.

DesignedContentChanged

Occurs when user modifies any aspect of the control being designed.

DesignerHostChanged

Occurs when designer host changes, for example if new form is loaded.

LoadingErrorOccured

Occurs when there is a parse error of the design code during loading.

NavigateToUserMethodRequested

Occurs when form designer is requested to navigate to the event handler. For example, when user double clicks on the control.

ReferencedAssembliesChanged

Occurs when ReferencedAssemblies list is changed.

SelectionChanged

Occurs when user selects different control in the designer.

ShowPropertiesRequested

Occurs when user request to open Property Window.

TypeDiscoveryRequested

Occurs when IFormDesignerControl tries to descover types.

ViewCodeRequested

Occurs when user request to view designer source code.