Hosting in WinForms step by step
Put a form together with WinFormFormHost.
In this documentation
- Beep.Forms
- Architecture
- Authoring in the Object Navigator
- WinForms runtime
- WPF runtime
- End-to-end example
- Remote UI limitations
- Overview
- Context menus
- Blocks and items
- Triggers
- Lists of values
- Validation
- Master detail
- Navigation and queries
- Alerts, editors and timers
- Calling other forms
- Form menus
- Hosting in WinForms step by step
- Hosting in WPF step by step
- Saving and loading forms
- The IDE toolbar and dialogs
- Troubleshooting
This page lists the steps in order. The runtime classes are described on the WinForms runtime page.
- Create the host:
new WinFormFormHost { Dock = DockStyle.Fill }. - Add each
BlockDefinitiontoDefinition.Blocks. - Add a
WinFormBlockHostwithBlockName,DefinitionandDock, and aWinFormBlockNavigationBarwithBlockName. SetblockHost.NavigationBarbefore the manager is assigned. - Add the controls to the form.
- Assign
_formsHost.FormsManager = manager. This registers the blocks, connects the surfaces, refreshes the status bar and draws the menu. - Assign
FormFactoryif the form calls other forms. - Call
RegisterBeepFormsMetadata(), the generated method that registers triggers, lists of values, rules and relations. - After the form loads, call
ExecuteQueryAsync("Ord")andMoveFirstAsync("Ord").
Assigning a manager is transactional. If it throws, the attempted blocks are unbound and the previous manager is restored.
Creating the manager
var manager = new FormsManager(editor);
Application.Run(new OrderEntryForm(manager));
A fuller constructor takes optional services, including alertProvider and editorProvider.
Block names
Block names are not case sensitive. Registering a second block with the same name throws "A block named 'name' is already registered." Automatic discovery skips duplicates without an error.
Threading
WinFormFormHost checks the owner thread. Its handle must be created on the thread that owns it before another thread uses it.
Status bar
WinFormFormStatusBar has Bind, Unbind and SyncFromManager and segments named PositionSegment, ModeSegment and ChangedSegment.