How to: Give every page the same header
Give an application shell one header for all its pages - title, subtitle, the commands of the page and a status - instead of buttons and labels that each page or the shell places and measures itself.
Requires WKL Forms Object Library 1.46 or later.
Solution overview
- One
WklActionBarin the shell, above the subform that shows the pages (sfPage). - The shell sets the page's commands when it shows a page: one JSON text per page, or
ClearCommandsandAddCommand. - One event procedure runs every command:
CommandClick(Key)passes the key to the procedure that knows what each key does. - The state of the record enables and disables commands by key, for example after the list's
CommandStateChange.
Implementation
In the module of the shell form frmShell (bar barShell, page subform sfPage):
Option Compare Database
Option Explicit
Public Sub ShowPage(ByVal pageForm As String)
Me!sfPage.SourceObject = pageForm
With Me!barShell.Object
.Caption = Me!sfPage.Form.Caption
.Subtitle = Nz(Me!sfPage.Form.Tag, "")
.ClearCommands
Select Case pageForm
Case "frmPersons"
.AddCommand "new", "&New", "E710", wcpStandard, "^N"
.AddCommand "edit", "&Edit", "E70F"
.AddCommand "delete", "&Delete", "E74D"
.AddCommand "issue", "&Issue key…", "E8D7", wcpPrimary
.AddCommand "issue-test", "Issue &test key…", "", , , "issue"
.AddCommand "revoke", "&Revoke key…", "", wcpMenu
.AddCommand "columns", "Reset c&olumns", "", wcpMenu, , , , True
End Select
.AddCommand "export", "E&xport…", "EDE1", wcpRight
.AddCommand "refresh", "Re&fresh", "E72C", wcpRight, "{F5}"
End With
End Sub
Private Sub barShell_CommandClick(ByVal Key As String)
Select Case Key
Case "new": Me!sfPage.Form!grdList.Object.NewRecord
Case "edit": Me!sfPage.Form!grdList.Object.EditSelected
Case "delete": Me!sfPage.Form!grdList.Object.DeleteSelected
Case "refresh": Me!sfPage.Form!grdList.Object.Requery
Case "export": Me!sfPage.Form!grdList.Object.ShowExportDialog
Case Else: RunPageCommand Key
End Select
End Sub
' Called by the page after its list changed what can be done (CommandStateChange of WklGrid).
Public Sub ListStateChanged(ByVal grid As Object)
With Me!barShell.Object
.CommandEnabled("new") = grid.CanAdd
.CommandEnabled("edit") = grid.CanEdit
.CommandEnabled("delete") = grid.CanDelete
End With
End Sub
Private Sub RunPageCommand(ByVal Key As String)
' The commands only this page has, for example opening a dialog.
End Sub
Remarks
- A shell that keeps one set per page can store each as JSON text and assign it with
.Commands = text; a text with an error is refused as a whole and the bar keeps its commands. - The status pill shows what the whole application is doing, for example
.StatusText = "Updated " & Format(Now, "hh:nn:ss")with.StatusKind = wskOk. - List each shortcut once: in the bar (
Shortcutof a command) or inWklDockLayout.ShortcutKeys, not in both. - The bar's band takes
BackColorandForeColor; the command row keeps the window color, so the buttons stay readable on a dark band. - Commands set by code in form view do not mark the form as changed; commands set in design view (by code or the designer) are stored with the form.
Related topics
en/wiki/msaccess/comctl/how-to/give-every-page-the-same-header.txt · Zuletzt geändert: von Wolfgang van der Stille