Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

Focus on Building the Console - Part 2 of 2

Written by Brent Pinkley  [author's bio]  [read 40297 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3  Page 4 

OK, that was a little bit of a workout, but it makes life a little easier for anyone using the application, which is always a design goal, right? If this is not enough, then you might want to check out how to add searching capability to your list view in the article "Find Items in ListView, ListBox, and ComboBox Controls" by Christian Forsberg.

Why Not Create a Cool MenuBar as Well

Why have a boring menu bar when you can add some extra functionality and ease of use to your application by using sub-menus, menu buttons for quick access to key functions, and visual cues, such as checked or context-enabled options? A little goes a long way toward making your application easy to use, so the effort is definitely worth it.

Adding top level menu items is pretty straight forward, and continuing with sub menu items is not much more involved:

' Instantiate menu as menu bar control
' and assign name and caption
Set mnuFile = mnuConsole.Controls.AddMenu("File", _
"mnuFile")

' Add first top-level menu item
mnuFile.Items.Add 1, "mnuFileNew", "New"

' Add sub menu items
mnuFile.Items(1).SubItems.Add 1, _
"mnuFileNewQueue", "Queue"
mnuFile.Items(2).SubItems.Add 2, _
"mnuFileNewMessage", "Message"
mnuFile.Items(3).SubItems.Add 3, _
"mnuFileNewXML", "XML Contact"

' Continue adding top-level menu items
mnuFile.Items.Add 2, "mnuFileRead", "Read"

' Clean up
Set mnuFile = Nothing

You now have nested menus! Where it starts to get interesting is adding menu bar buttons for commonly used tasks. In the Console application, there are buttons to allow quick access to create a queue, message or XML contact. One thing to remember is that you will want to associate an image list control with the menu bar if you plan on using customized images. The concept is basically the same as adding a menu bar menu, but you will be setting image information instead of text:

' Instantiate menu bar buttons
Set mnuSpacer = _
mnuConsole.Controls.AddButton("Spacer")
Set mnuQueue = _
mnuConsole.Controls.AddButton("cmdQueue")
Set mnuMessage = _
mnuConsole.Controls.AddButton("cmdMessage")

' Configure spacer
mnuSpacer.Width = 80
mnuSpacer.Style = mbrSeparator

' Configure buttons
mnuQueue.Image = 8
mnuQueue.Style = mbrDefault
mnuMessage.Image = 9
mnuMessage.Style = mbrDefault

The style influences how the button appears on the menu bar. The mbrSeparator creates a vertical line, whereas the mbrDefault creates a default button with an image. Other options include mbrCheck, which would have a depressed state for the button to let you know when it has been selected.

When working with menus that appear across several frames, you will want to consider using visual cues to let the user know which options are in place and valid for the current frame. For options you can toggle, such as gridlines, you can place a check mark by the menu item when the option is "on":

' Reference the menu
Set mnuView = mnuConsole.Controls("mnuView")

' Reference the menu item
Set mnuViewItem = mnuView.Items("mnuViewGridlines")

' Update checked status
If mnuViewItem.Checked Then
mnuViewItem.Checked = False
Else
mnuViewItem.Checked = True
End If

In a similar way, you can disable menu options that are not valid for the current frame:

Private Sub ToggleViewMenu _
(ByVal bolState As Boolean)

Dim mnuView As MenuBarLib.MenuBarMenu
Dim mnuViewItem As MenuBarLib.Item

' Reference View Menu
Set mnuView = mnuConsole.Controls("mnuView")

' Set Enabled state for Full Row item
Set mnuViewItem = _
mnuView.Items("mnuViewFullRow")
mnuViewItem.Enabled = bolState

' Set Enabled state for Gridlines item
Set mnuViewItem = _
mnuView.Items("mnuViewGridlines")
mnuViewItem.Enabled = bolState
End Sub

And there you have it - a fully functional menu, with intuitive cues and quick access for common functions!

Previous Page  Next Page