FormDesignerControl Class
Definition
Represents a control supports all standard form editing operations with controls.
Implements
Syntax
[ToolboxBitmap(typeof(FormDesignerControl), "Images.FormDesignerControl.Icon.bmp")]
public class FormDesignerControl : Control, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable, IFormDesignerControl, ITypeDiscoveryService
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+
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
Constructors
FormDesignerControl() | Initializes a new instance of the |
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 |
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 | When implemented by a class, gets a boolean value indicating that designer is currently being loaded. |
IsModified | Represents a value indicates whether designer content has been modified since last save. |
IsSmartDiffCodeSerializationRequired | Gets or sets method used to identify whether |
Options | Gets designer options like snap settings, grid size etc. |
PrimarySelection | Gets first selected component or control. |
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. |
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 |
Methods
CreateContext(IFormDesignerDataSource) | |
CreateDefaultKeyBindings() | |
CreateDesignerCommands() | |
Dispose(Boolean) | |
GetLocalizationLanguage() | Gets current culture information |
HandleKeyboardShortcuts(Keys, Keys) | |
RaiseComponentChanged(Object) | |
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) | |
TryAddComponentAssemblyReferences(IComponent) | |
TryFindCommandKeyBinding(Keys, Keys) | |
ViewCode(Object, EventArgs) |
Events
CommandStateChanged | Occurs when state of designer commands changes (for example when undo stack becomes available). |
CompilerErrorClick | Occurs when 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. |
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. |
DesignSurfaceKeyDown | Occurs when user presses a key when design surface is focused. |
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 | |
SelectionChanged | Occurs when user selects different control in the designer. |
ShowPropertiesRequested | Occurs when user request to open Property Window. |
TypeDiscoveryRequested | |
ViewCodeRequested | Occurs when user request to view designer source code. |
Explicit Interface Implementations
ITypeDiscoveryService.GetTypes(Type, Boolean) |