In VB, the MDI (MultipleDocumentInterface, multi-window program) form is defined like this: "The MDI form serves as the background window of a program and contains a form with the MDIChild attribute set to True." In a VB program, there can be at most one MDI parent form, and there can be multiple MDI child forms; the method to create an MDI parent form is to select "NewMDIForm" in the File menu of VB.
When the MDI program is running, if the child window has a menu, then when the child window is activated, the child window's menu will automatically replace the parent window menu; when the child window is minimized, the child window will appear in the MDI parent window. icon.
The emergence of the universal graphical interface of Windows enables computer users to use various Windows software easily without special learning; not only that, it is also a standard that program designers must follow when designing the interface of Windows programs. It greatly reduces the burden of program designers, allowing them to focus on solving and implementing problems.
The emergence of Visual Basic has further simplified the design of Windows program interfaces. Only a very small amount of code is needed to implement the interface of standard Windows applications. However, if you do not understand the principles of Windows program interface design, or are not familiar with the skills of interface programming under VB, it will be difficult to design and implement an interface that both conforms to general standards and is unique. Principles of Interface Design Interface design has general principles, the most important ones are:
The interface needs to be consistent. The principle of consistency is the easiest to violate in interface design, and also the easiest to modify and avoid. For example, the same terminology must be used in menus and online help; dialog boxes must have the same style.
There should be shortcuts for common operations. Common operations are used frequently and the length of the operation sequence should be reduced. For example, set shortcut keys for common file operations such as opening, saving, and saving as. Providing shortcuts for common operations will not only improve the user's work efficiency, but also make the interface simple and efficient in functional implementation.
Provide simple error handling. The system must have error handling capabilities. The system should be able to detect errors when they occur and provide simple and understandable error handling capabilities. The status of the system does not change after an error occurs, or the system needs to provide error recovery guidance.
Provide information feedback. There should be information feedback for important operations of the operator. There is no requirement for feedback on commonly used and simple operations, but for infrequently used and crucial operations, the system should provide information feedback.
Operation is reversible. The operation should be reversible. This is useful for operators without specialized knowledge. A reversible action can be a single operation or a relatively independent sequence of operations.
Well designed online help. Although online help is not essential for skilled users, it plays a very important role for most unskilled users.
Menu Design Principles and Programming
Menu design has the following general principles:
Organize menus according to system functions.
Choose a wide and shallow menu tree rather than a narrow and deep menu tree.
Group the menu options according to their meaning; and sort them according to certain rules. Menu option titles should be short, clear, and preferably start with a keyword.
Shortcut keys need to be set for frequently used options. Combining the above principles, menu programming has the following technologies and techniques:
Grouping of menu options
In VB, the grouping of menu options is achieved by dividing the menu bar with horizontal lines. Add a menu item with a Caption attribute of "" at a certain position in the menu, and it will appear as a horizontal line on the menu. In many cases, the same function menu can be divided into several groups according to the functions of the menu options. In this case, dividing horizontal lines can be used to group the menu items.
Settings of shortcut keys for common options
Open the menu design window (MenuDesignWindow). There should be a corresponding shortcut key (Shortcut) list for each menu option. Just select one in the list. It should be noted that shortcut keys for menus with submenus or top-level menus cannot be defined in this way. According to the Windows interface design principles, the shortcut key for the top menu is in the form of the Alt letter key. Its implementation method will be described later.
For some commonly used function menu items, there are conventional shortcut keys. For example, use CTRL O to open a file, CRTL S to save a file, CTRL P to print, and so on.
After defining a shortcut key for a menu option, a text representation of the shortcut key appears behind the option on the menu.
Enable and disable, visible and hidden menu options In order to express some special functions of menu options, the enable and disable, visible and hidden attributes of menu options may be used. When the function represented by an option cannot be realized for some reason, the option should be prohibited from being selected. Menu options are enabled and disabled by changing the Enabled attribute of the option. For example, assuming the menu option is named nmuName, disabling this option can be implemented as follows:
mnuName.Enabled=False
In the same way, you can hide an option by using
mnuName.Visible=False
To achieve this, to make a hidden option visible again use
mnuName.Visible=True
accomplish.
Hiding and restoring visibility of menu items is often used in the implementation of dynamic menus.
Dynamic loading of menu items
Dynamic loading of menu items means that the number of menu items is not fixed and can be loaded dynamically when needed. The simplest example is the list of recently opened files in the File menu. Before opening a file for the first time, the list is empty and does not appear in the file menu; after opening a file, the list is no longer empty, and the menu item representing the opened file appears in the file menu.
In the above example, the subscript attribute (Index), title attribute (Caption), visible attribute (Visible) of the menu item and the loading method (LoadMethod) of the menu item are comprehensively used.
The specific implementation process is as follows:
Add a menu item to the file menu with an arbitrary title, and assume that the menu item's Name attribute is opened_files_list;
Change the visible attribute of the menu item opened_files_list so that opened_files_list.Visible=False
Change the subscript attribute of the menu item opened_files_list so that
opened_files_files_list.Index=0
Control the dynamic loading of the menu item opened_files_list in the program.
Suppose you want to display the file name of the second file that has been opened, and the file name is stored in a file name array opened_file_name. The following code implements this function:
Loadopened_files_list(1)
opened_files_lise(1).Caption="&2" opened_file_name(1)
opened_files_list(1).Visible=True
It should be noted that the Load method cannot be used for menu items whose subscript is 0. Because the menu item has been loaded into the memory when the program is executed; in addition, the "&" character in the title attribute character of the menu item has a special meaning, and its function is to display the attribute string. At the same time, the "&" itself is not displayed, but the character immediately following the "&" is displayed with an underline, and the character becomes a hotkey.
If the menu item whose index is not 0 is no longer needed, in order to reduce the occupation of memory resources, you can use the Unload method to unload it from the memory; similarly, you cannot use Unload to unload the menu item whose index is 0.
Implementation of pop-up menu (PopupMenuMethod)
The menu designed in the menu design window (MenuDesignWindow) in VB is a drop-down menu. The drop-down menu is a menu that the user can pull out after making a selection on the top menu bar at any time, while the pop-up menu is a menu that appears after clicking the mouse button in a certain area of the program interface. In some cases, pop-up menus can make system functions more concise and efficient, making them easier to use.
The pop-up menu of Widnows program generally appears when the user clicks the mouse button on the desktop of the program. Pop-up menus are mostly used to implement additional or enhanced functions of the system. The contents of the pop-up menu can change depending on where the mouse button is clicked. Since the pop-up menu will cover part of the screen, the text in the menu should be shortened as much as possible.
In VB, the implementation of pop-up menus requires the use of drop-down menu design technology and the PopupMenu method. The specific method is:
Design the pop-up menu of the corresponding form in the menu design window (MenuDesignWindow). It should be noted that the menu to be popped up must have at least one submenu; therefore this menu cannot have shortcut keys, and the Checked attribute must be False. Then change the pop-up menu's Visible property to False.
Add the following code to Form_Click of the form with the designed pop-up menu (assuming that the Name property of the pop-up menu is mnuExample):
SubForm_Click()
PopupMenumnuExample
EndSub
If you require that the menu can only be activated by pressing the left or right mouse button, you must add the following code to Form_MouseDown:
SubForm_MouseDown(ButtonAsInteger,ShiftAsInteger,xAsSingle,yAsSingle)
IfButton=2thenButton=2 means right mouse button
PopupMenumnuExample
EndIf
The complete syntax of PopupMenu is:
[Form.]PopupMenumenuname[flags[,x[,y]]]
Changing the value of flags can control the appearance of the pop-up menu. Flags have two sets of values. The first set of values is used to control the display mode of the menu, including POPUPMENU_LEFTALIGNPOPUPMENU_CENTERALIGN and POPUPMENU_RIGHTALIGN, which respectively represent the display mode with x as the left boundary, x as the center and x as the right boundary. And using x as the left boundary is the default method; another set of values is used to control the selection method of menu items, including POPUPMENU_LEFTBUTTON and POPUPMENU_RIGHTBUTTON, which respectively indicate left-click selection and left/right-click selection, and left-click selection is the default. way. The value of Flags is obtained by ORing the above two sets of values. For example, if the display is required to be left aligned and the left button is selected, then it should be:
flags=POPUPMENU_LEFTALIGNORPOPUPMENU_LEFTBUTTON
x and y are used to define the position of the menu pop-up. The default is the position of the mouse point.
Other properties of menu items
Use the ALT letter key to activate the top-level menu, or use the letter key to activate a menu item after the menu is activated. You must learn to use &. & is used in the title attribute (Caption) of the menu item. Its usage and function are the same as those in Windows programs compiled in C language.
Sometimes you want the space between top-level menus to be larger, or a top-level menu to appear at the right end of the menu bar. In this case, you need to use a menu whose title attribute is a space. If the title of a menu is composed of multiple spaces, then the menu will occupy the space corresponding to the number of spaces on the menu bar, and the menus behind it will also be moved back sequentially; if the Visible property of this menu is False , then it is as if it does not exist.
Window design principles and examples
Below is an example of floating window technology. In order to attract the user's attention, or to ensure that windows containing important information are not covered by other windows, floating window technology is used to create a "TopMost" window. The specific method is:
(1) Add the following statement to the VB program:
DeclareFunctionSetWindowPosLib"user"(Byvalh,Byvalhb,Byvalx,Byvaly,By
valcx,Byvalcy,Byvalf)AsInteger
GlobalConstSWP_NOMOVE=2
GlobalConstSWP_NOSIZE=1
GlobalConstHWND_TOPMOST=1
GlobalConstHWND_NOTOPMOST=2
GlobalConstFLAGS=SWP_NOMOVEOrSWP_NOSIZE
(2) Suppose you want to set the form frmExample to be the window that is always at the front. Just set the form in the Form_Load of the frmExample form.
Add the following code to the process:
Dimsuccess
success=SetWindowPos(frmExample.hWnd,HWND_TOPMOST,0,0,0,0,FLAGS)
If you want to cancel the feature that is always on top, you can execute the following code:
success=SetWindowPos(frmExample.hWnd,HWND_NOTOPMOST,0,0,0,0,FLAGS)
Success is not equal to 0, which means SetWindowPos is executed successfully.
In an MDI program, one window is the parent window of all other windows, and each child window completes a relatively independent function, just like a combination of multiple independent tools. In this regard, MSWord and Windows' FileManager are the best examples. ->