VB to create a cool personalized menu (1)

zhaozj2021-02-16  60

VB to create a cool personalized menu (1)

As we all know, MS Office 2003 has been launched for a while, but we will not forget that Office XP has just launched the refreshing menu to leave us a deep impression. The protrusions of the suspended icon, unusual menu items are filled, not only makes the office families, but also make the majority of programmers and programming enthusiasts produce a strong interest in the production of this style of menus. So, in this article, we will study how to use VB how to make this style of this style, in the end of the article, I will give the download address of the source code. In fact, after understanding the principles, whether it is VB, VC or Delphi, you can make an XP style menu. Not only that, we can also produce a more filled number of other-style menus, such as 3D stereo style, gradient style, colorful styles, etc. Only I can't think of it, I haven't been can't do. FOLLOW ME!

Now, I want to say what we have to do now. In fact, we just have a menu class. But everyone will understand that only a menu class is not enough, we need a program, or more detailed, is a form to test our menu class. During my personal development process, I am writing a menu class, the post-written test form, but in order to let everyone first appreciate what is convenient to write, let us take a look Test form:

(1) Open VB, create a new "Standard EXE" project.

(2) The following is the control:

Component name

Attributes

value

FORM

Name

CAPTION

Frmmain

Menu example

Frame

Name

CAPTION

FraStyle

Menu style

Label

Name

CAPTION

lblhelp

Right click on the blank of the form

Optionbutton

Name

CAPTION

Index

OpnStyle

WINDOW standard

0

Optionbutton

Name

CAPTION

Index

OpnStyle

XP style

1

Optionbutton

Name

CAPTION

Index

OpnStyle

3D stereo style

2

Optionbutton

Name

CAPTION

Index

OpnStyle

Gradient style

3

Optionbutton

Name

CAPTION

Index

OpnStyle

Colorful style

4

In fact, adding a frame on the form, then add an OptionButton control array in Frame, used to set the menu style, there is a Label, which only shows a line prompt text, very simple.

(3) Form code:

Option expedition

Private Declare Function GetCursorpos LIB "User32.dll" (LPPOINT AS POINTAPI) AS Long

Private Type PointApi

X as long

Y as long

End Type

Dim Menu as cmenu

Private sub flow_load ()

'Initialization menu and add menu items

Set menu = new cmenu

Menu.createMenu

Menu.Additem "open", "Images / Open.ico"), "Open", MIT_STRING

Menu.additem "Save", LoadPicture ("Image / Save.ico"), "Save", MIT_STRINGMENU.Additem "Print", LoadPicture ("Image / Print.ico"), "Print", MIT_STRING

Menu.Additem "Find", LoadPicture ("Images / Find.ico"), "Find", MIT_STRING

Menu.Additem "Sep1", LoadPicture (), "" ", MIT_SEPARATOR

Menu.additem "undo", LoadPicture ("IMAGES / undo.ico"), "Undo", MIT_STRING

Menu.Additem "Redo", LoadPicture ("Image / Redo.ico"), "Repeat", MIT_STRING

Menu.additem "Sep2", LoadPicture (), "" ", MIT_SEPARATOR

Menu.Additem "Cut", LoadPicture ("Images / Cut.ico"), "Cut", MIT_STRING

Menu.additem "Copy", LoadPicture ("Images / Copy.ico"), "Copy", MIT_STRING

Menu.Additem "Paste", LoadPicture ("Image / Paste.ico"), "Paste", MIT_STRING

Menu.Additem "Sep3", LoadPicture (), "" ", MIT_SEPARATOR

Menu.Additem "Check", LoadPicture ("Image / Check.ico"), "A Checkbox", MIT_CHECKBOX

Menu.additem "exit", LoadPicture ("Image / EXIT.ICO"), "Exit", MIT_STRING

End Sub

Private Sub Form_MouseDown (Button As Integer, Shift As Integer, x as single, y as single)

'Click on the right to build a pop-up menu

If Button = Vbrightbutton Then

DIM POS as PointApi

GetCursorpos POS

Menu.popupmenu Pos.x, Pos.y, Popup_LEFTALIGN OR POPUP_TOPALIGN

END IF

End Sub

Private Sub Form_Unload (Cancel AS Integer)

'Release resource, uninstall the form

Set menu = Nothing

DIM FRM AS FORM

For Each FRM in Forms

Unload FRM

NEXT

End Sub

PRIVATE SUB OPNSTYLE_CLICK (INDEX AS INTEGER)

'Setting up menu style

SELECT CASE INDEX

Case 0 'Windows Standard

Menu.style = style_windowscase 1 'XP style

Menu.Style = style_xp

Case 2 '3D stereo style

Menu.Style = style_3d

Case 3 'Gradient Style

Menu.style = style_shade

Case 4 'colorful style

Menu.Style = Style_Colorful

End SELECT

End Sub

A CMenu class object is created in the code, and our programming focuses on the cMenu class, the code above simply calls CMenu. In the following article, we will see that there are more than 30 methods and properties of CMenu for us to call, and its style property only provides five kinds of built-in style. In practical applications, we can use the method of cMenu class and The property produces a variety of style menus to add flowers on their own programs.

(4) Run the results:

This article is just a throwing brick, let everyone sneak peek, and experience the charm of this menu class in advance. In the next article, we will continue to discuss the production of personalized menus, not the same, our focus will be the CMenu class. :)

(to be continued)

转载请注明原文地址:https://www.9cbs.com/read-16884.html

New Post(0)