Visual Assistance With Menu Items |
|
Visual Assistance With Menu Items |
Introduction |
After creating a menu (main menu and popup menu), there are various actions you can perform to improve it and there are many ways you can enhance the user's experience with your application. Menus provide various features such as access keys and shortcuts. There are also other things you can do such as grouping menus. Although some of these actions are not required to make an application useful, they can be necessary to make it more professional. |
Practical Learning: Introducing Menu Assistance |
//--------------------------------------------------------------------------- void __fastcall TForm1::mnuFileNewPropertyClick(TObject *Sender) { RealEstateProperty->ShowModal(); } //---------------------------------------------------------------------------
//--------------------------------------------------------------------------- void __fastcall TForm1::mnuFileExitClick(TObject *Sender) { Close(); } //---------------------------------------------------------------------------
A menu item can display an letter underlined. Using this letter allows the user to access the menu using a keyboard. For example, if the letter F is underline in a File menu as in File, the user can access the File menu by pressing the F10 key, then F. To create this functionality, choose a letter on the menu item and precede it with the & character. For example, &File would produce File. You can apply the same principle if you are programmatically creating the menu. Here are two examples: //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { TMainMenu *mnuMain = new TMainMenu(this); TMenuItem *mnuFile = new TMenuItem(this); TMenuItem *mnuFileNew = new TMenuItem(this); TMenuItem *mnuFileOpen = new TMenuItem(this); mnuFile->Caption = L"&File"; mnuFileNew->Caption = L"&New"; mnuFile->Add(mnuFileNew); mnuFileOpen->Caption = L"&Open"; mnuFile->Add(mnuFileOpen); mnuMain->Items->Add(mnuFile); } //--------------------------------------------------------------------------- |
After creating the menu, to use it, the user can press Alt or F10:
A shortcut is a key or a combination of keys that the user can press to perform an action that can also be performed using a menu item. When creating a menu, to specify a shortcut, use the ShortCut property. To visually specify a shortcut, in the menu designer, click the menu item. In the Object Inspector, click ShortCut and click the arrow of the field, a window would come up:
To specify a shortcut, select from that list. To programmatically create a short key, call the ShortCut() function. Its syntax is: TShortCut ShortCut(Word Key, TShiftState Shift); This function takes two arguments. The Key argument is a letter passed as a Word. The second argument specifies whether you will use the Ctrl key, the Shift key, or a combination of a Ctrl + Shift key. To provide this value, apply the << operator to the TShiftState() function. Specify the Shift key as ssShift or the Ctrl key as ssCtrl. Here are two examples: //---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TMainMenu *mnuMain = new TMainMenu(this);
TMenuItem *mnuFile = new TMenuItem(this);
TMenuItem *mnuFileNew = new TMenuItem(this);
TMenuItem *mnuFileOpen = new TMenuItem(this);
mnuFile->Caption = L"&File";
mnuFileNew->Caption = L"&New";
mnuFileNew->ShortCut = ShortCut(Word(L'N'), TShiftState() << ssCtrl);
mnuFile->Add(mnuFileNew);
mnuFileOpen->Caption = L"&Open";
mnuFileOpen->ShortCut = ShortCut(Word(L'O'), TShiftState() << ssCtrl);
mnuFile->Add(mnuFileOpen);
mnuMain->Items->Add(mnuFile);
}
//---------------------------------------------------------------------------
This would produce:
|
When a user has clicked a menu item, an action is supposed to occur. In some cases, an intermediary action is necessary before performing or completing the action. To indicate that an intermediary action is needed for the action related to the menu item, Microsoft standards suggest that the menu's text be followed by three periods. There is no programmatic relationship between the application and the menu item that displays three periods. It is only a suggestion to show them. Therefore, when creating a menu item, if you know that an intermediary action will be used to perform or complete the actual action, add three periods on the right side of its text. Here is an example: //---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TMainMenu *mnuMain = new TMainMenu(this);
TMenuItem *mnuFile = new TMenuItem(this);
TMenuItem *mnuFileNew = new TMenuItem(this);
TMenuItem *mnuFileOpen = new TMenuItem(this);
TMenuItem *mnuTools = new TMenuItem(this);
TMenuItem *mnuToolsOptions = new TMenuItem(this);
mnuFile->Caption = L"&File";
mnuFileNew->Caption = L"&New";
mnuFileNew->ShortCut = ShortCut(Word(L'N'), TShiftState() << ssCtrl);
mnuFile->Add(mnuFileNew);
mnuFileOpen->Caption = L"&Open";
mnuFileOpen->ShortCut = ShortCut(Word(L'O'), TShiftState() << ssCtrl);
mnuFile->Add(mnuFileOpen);
mnuMain->Items->Add(mnuFile);
mnuTools->Caption = L"&Tools";
mnuToolsOptions->Caption = L"&Options...";
mnuTools->Add(mnuToolsOptions);
mnuMain->Items->Add(mnuTools);
}
//---------------------------------------------------------------------------
This would produce:
Because the three periods indicate to the user that an intermediary action will be performed, when implementing the code for the menu item, make sure you provide that intermediary action.
|
|
|||||
|
|
||
Home | Copyright © 2010-2016, FunctionX | |
|