VB memorandum (11) menu Toolbar

Source: Internet
Author: User

Menu Editor

Title and name

Title: used for display and selection on the menu.

Name: it is not displayed on the menu and is used to manipulate the action of the corresponding title menu in the program code.

"Coordination location"

Allow to selectNegotiatepositionAttribute. This attribute determines whether or not to display the menu in the container form.

This msdn is too rough to understand what it means after checking for N long.

There is a menu or a container to be added on a form (the control or tool board Ole is added). The OLE container can be the insert of another program, for example, the insert is Excel.

At runtime, When you double-click the container, the Excel file will be called. the Excel file itself has a Menu B, which will be displayed in both form a and form a on the original form, how can we arrange them?

The Coordination position is used for this purpose, or none (the original menu a disappears and is replaced by Menu B in Excel)

It is either left, center, right, that is, mixed with Menu B, in the left, center, right of B.

The detailed statement is as follows:

Set a value to determine when the linked object of the form (created and managed by another application, and then linked to the object in the Visual Basic Application) or

Embedded objects (objects created by other applications and then embedded in Visual Basic Applications) are active, and whether the top menu control set by the user is displayed when the menu is displayed.

The list has four options:

0 (none) -- (default) the menu of the form is not displayed in the menu bar.
1 (left) -- The menu of the form is displayed on the left of the menu bar.
2 (middle) -- The menu of the form is displayed in the middle of the menu bar.
3 (right) -- The menu of the form is displayed on the right of the menu bar.

For example, add an Excel worksheet object to the form. If you select 3 (right,

Run the program. When you double-click to activate an Excel worksheet object, the top-level "file" menu set by the user is displayed in the middle of the embedded object menu, for example:

Index: used only for menu arrays.

Create a menu array: Create a menu array with the same name for multiple menu items, and then set their indexes.

The menu array must be:

The name must be the same and a unique index must be added.

It must be placed at the same level and consecutively. Even if there is a separator line, the separator line must also be an element in the menu array.

The index must be in ascending order. It can be a non-consecutive index but must be upgraded (the index must be placed continuously)

Note:

1. Coordinate recalculation. When a menu is available, the coordinates are in the lower left corner of the menu bar (0, 0 ).

2. The menu pattern is displayed. When the menu is displayed, the statements under popupmenu are suspended until the menu is canceled or the following statements are executed after the menu is selected and executed.

Check menu and cascade menu

Check, set it to checked

Cascade and set its sub-menu (up to 5 levels)

Pop-up menu

First, you must have a specific menu, and then use the pop-up event to call this menu, that is, the pop-up menu.

Object. popupmenu menuname, flag, X, Y, [boldcommand]

Object menu host, on which object is displayed

The style of the Flag pop-up menu, left, center, right (relative to x, y)

Position of the pop-up menu X and Y

Boldcommand menu name (this name will appear in)

Note: The pop-up menu can be hidden in the original main menu and called in the pop-up as needed.

The call process is as follows: first, hide the hidden menu

Menu Design

Getmenu gets the menu handle (if a form has a menu)

Getmenu form handle example: getmenu form1.hwnd

Prototype: Private declare function getmenu lib "USER32" alias "getmenu" (byval hwnd as long) as long

Getsubmenu: Get the pop-up menu handle and position in the menu (the first entry is 0, and the following increments ).

Getsubmenu menu handle. Return the position of the pop-up menu in the menu. Example: getsubmenu (menuhwnd, 0)

Prototype: Private declare function getsubmenu lib "USER32" alias "getsubmenu" (byval hmenu as long, byval NPOs as long) as long

Setmenuitembitmaps

Private declare function setmenuitembitmaps lib "USER32" alias "setmenuitembitmaps"

(Byval hmenu as long,
Byval nposition as long, byval wflags as long, byval hbitmapunchecked as long, byval hbitmapchecked
As long) as long

Hmenu handle

Nposition: ID of the menu entry to be set

Wfags select mf_bycommand or mf_byposition

Hbitmapunchecked unchecked

Figure displayed when hbitmapchecked is checked

Example: setmenuitembitmaps (sub-menu handle, 0, mf_byposition, new. Picture, oldpicture)

The Beautification menu also has two APIs.

Getmenuinfo

Setmenuinfo

Toolbar and coolbar

Generally associated with imagelist to obtain the corresponding icon

If you want to add or delete an associated imagelist, you must disconnect the associated imagelist and add or delete it before joining it.

The toolbar of the drop-down menu must be set to 5-tbrdropdown in the style, and the buttons can be grouped to 2-tbrbuttongroup.

The grouping button uses select case to judge and process button. index.

Beautification

Using coolbar for beautification is equivalent to a container where the toolbar is placed in the coolbar for relevant settings.

How does one trigger an event from the drop-down menu on the toolbar?

Select the buttonmenuclick event. The key or tag keyword indicates that the menu is clicked.

Private sub toolbar1_buttonmenuclick (byval buttonmenu as mscomctllib. buttonmenu) If buttonmenu. Key = "C" then msgbox buttonmenu. Parent & "C" 'drop-down menu parent name and its own keyword end ifend sub

Use toolbar, coolbar, and imagelist in combination (animation demonstration)

Status Bar

Statusbar

1. Add a bar based on the attribute (three styles can be set)

2. content, which can be set based on attributes or code

Form1.statusbar1. Panels (1). Text = "Author: brag"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.