Design Web Menu Components with VB.NET

xiaoxiao2021-03-06  44

The WINDOWS application is often inseparable from the menu. The application of the menu is very common, and the menu design is very simple, this is mainly because it has been prepared into a component package for direct calls in the programming language. However, it is impossible to use the menu to be used directly in the web program. It is necessary to write a lot of complex code. So many web programmers avoid these troubles as much as possible, replaced with other functions. However, this will affect the WEB style or even reduce the level of the program. Fact, we can also reject Windows menu design experience to develop a complete web menu component, and fully packaged for users directly, which is the same as the Windows menu. I use vbasic.net to develop a simulation window menu in practice to implement multi-level menu components on the web. The component has flexible, dynamic, multi-effect functions, users can design different style menus, support icons, select line, menu style self-setting; icon background, background picture, front background, dynamic tips, font, text, fast Key and other settings. Now the method and process it implemented is as follows: Implementation principle: Using VBasic.NET powerful component development function, set each menu line as a node, set different properties of the node. Control the content displayed by the menu in the custom event of the menu component, call the corresponding function. The development steps are as follows: 1. Start Visual Studio.net. Select the Visual Basic project in the new project, select the class library in the template, enter the class library file name in the name, such as MenUNUNUDE, then enter the class library development environment, rename the class1 to Menode. Second, define the public catenus MenOde, This class is for application software calls. Define the private variable of the class MenUnde_ImageURL, which indicates the node picture. Define the properties of the class MenUnde _parentID, the attribute parent node, and write their functions separately. Code is as follows: Public Class MenuNode: Inherits TableCellPrivate _ImageUrl As StringPrivate _ParentID As Int16 'parent node number Public Property ParentID () As Int16GetReturn ViewState ( "_ ParentID") End GetSet (ByVal Value As Int16) ViewState ( "_ ParentID") = ValueDim a As TableCellEnd SetEnd Property 'junction image public Property ImageUrl () As StringGetReturn ViewState ( "_ ImageUrl") End GetSet (ByVal Value As String) ViewState ( "_ ImageUrl") = ValueEnd SetEnd PropertyEnd class III define public class MenuView, class definitions The main body, attribute, method 1 of the menu, defines the MenuView class, which inherits the WebControl class. Since the MenuView class is a user-defined class, we have to customize your own events.

It also requires references INamingContainer (the only namespace Interface), IPostBackEventHandler (custom event interface) code is as follows: Public Class MenuView: Inherits WebControlImplements INamingContainerImplements IPostBackEventHandler 2, some of the attributes defined MenuView class 'background picture Dim _BackGround As String' type style Dim _Type As INT16 'Collection Subscript From 1 Start, Store Menu Public Shared Coll As New Collection () Defines the Type of Menu Number: Icons, Detection, Detection Background, Ormonary ENUM ETYPESIMAGEBACKCOLOR = 0ischeckbackColor = 1ischeck = 2None = 3End Enum 'menu table Public Shared Index as Int16' pointer to the selected menu item Dim _SelectIndex as Int16 'menu item selected background color Dim _SelectBackColor as System.Drawing.Color' icon background color Dim _IconBackColor as System.Drawing .ColorPublic Property selectIndex () As Int16GetReturn _SelectIndexEnd GetSet (ByVal Value As Int16) End SetEnd PropertyPublic Property SelectBorderStyle () As BorderStyleGetReturn ViewState ( "_ SelectBorderStyle") End GetSet (ByVal Value As BorderStyle) ViewState ( "_ SelectBorderStyle") = ValueEnd SetEnd PropertyPublic Property SelectbackColor () as system.drawing.colorgetreturn ViewState ("_ selectbackcolor") End GetSet (ByVal Value A s System.Drawing.Color) ViewState ( "_ SelectBackColor") = ValueEnd SetEnd PropertyPublic Property IconBackColor () As System.Drawing.ColorGetReturn ViewState ( "_ IconBackColor") End GetSet (ByVal Value As System.Drawing.Color) ViewState ( "_ IconBackColor" ) = ValueEnd SetEnd Property'Public Property Type () As ETypeGetReturn ViewState ( "_ Type") End GetSet (ByVal Value As EType) ViewState ( "_ Type") = ValueEnd SetEnd PropertyPublic Property BackGround () As StringGetReturn ViewState ( "_ BackGround") End GetSet (Byval Value As String) ViewState ("_ Background") =

Valueend STEND Property 3, some method of defining a MenuView class 'primating menu public subnew () me.backcolor = system.drawing.color.deEppinkme.Drawing.color.deEppinkme.Borderstyle = BorderStyle.outsetme.width = unit.pixel (250)' me. Width = unit.pixel (50) me.background = "" me.borderwidth = unit.pixel (0) me.type = 1END SUB 'Custom ONCHANGE event, the event is used to represent the functions completed by the user called menu item Public Event Change As EventHandler 'triggers an onchange event. Protected Overridable Sub Onchange (Byval E As Eventargs) RaiseEvent Change (ME, E) End Sub 'When implemented by a class, the server control can handle the event that the form is transmitted to the server. Public Sub RaisePostBackeVent (BYVAL Eventargument As String) Implements ipostbackeventhandler.raisePostBackeventonchange (New Eventargs ()) End Sub 'The source code in the component directly into the HTML file via the Render method and execute it directly in the client. It is mainly necessary to determine the menu item selected by the user, and process the situation. Show this menu body to hide other menu. '///

' /// presented this control to the specified output parameter.

'/// ' /// The HTML writer to be written protected overrides sub render (byval output as system.web.ui.htmltextwriter) MyBase. RENDER (OUTPUT) OUTPUT.WRITE (CHR (13) CHR (10)) DIM STR AS STRINGSTR = "