Bắt đầu một ứng dụng thiết bị Windows Mobile và đặt tên cho menuBehavior dự án. Từ các thiết kế mẫu, thêm hai nhãn để hình thành và đổi tên chúng lbCntTitle và lbCnt, tương ứng. Đặt Vị trí của lbCntTitle (0,40), Size (80,22), và văn bản '= Số lượt truy cập. Sau đó thiết lập Vị trí của lbCnt (90,40), Size (80,22), | Chapter 4 Start a new Windows Mobile device application and name the project menuBehavior. From the Form Designer add two Labels to the form and rename them IbCntTitle and IbCnt respectively. Set the Location of lbCntTitle to 0 40 Size to 80 22 and the Text to Counter . Then set the Location of IbCnt to 90 40 Size to 80 22 and the Text to an empty string. Next add menu items to the main menu. Table 4-2 lists the order in which MenuItems are added to the form and summarizes the settings of each MenuItem added to the example application. Table 4-2 Menuitems in the menuBehavior Example Name Parent Text mnuDone mainMenu1 Done mnuOptions mainMenu1 Options mnuR1 mnuOptions R1 mnuR2 mnuOptions Counter mnuSep mnuOptions - mnuR3 mnuOptions R3 mnuR4 mnuOptions Remove R5 mnuR5 mnuOptions R5 mnuCntinc mnuR2 inc mnuCntDec mnuR2 Dec Figure 14-13 presents the graphic layout of the UI and menu items. If you examine the code generated by Visual Studio 2005 in the file then you will see that the hierarchy of the menu items is achieved by adding each menu item to the Menuitems collection of its parent. For example mnuCntinc and its parents and grandparents are constructed as follows . . As you can see the top-right menu mnuOptions is added to mainMenul and it contains mnuR2 which in turn contains mnuCntinc. In the example the function of mnuSep is to create a separator between menu items. This is easily achieved by setting the Text property of mnuSep to -. Next you will learn how to dynamically change menu items at runtime. For example when users select mnuR4 mnuR5 is removed and mnuR4 will therefore be disabled. 80 User Interface and Input Figure 4-13 From the Form Designer click mnuOptions to show the Menuitems directly attached to it. Then doubleclick mnuR4. Visual Studio 2005 will then automatically generate a stub of the event