QQ interface Everyone is not unfamiliar with it? Ctlistbar is a very good third party control, using it we can easily make a like QQ interface. In this section, we will build a cool QQ menu by learning from the basic usage of the Ctlistbar control and referencing an example.
The Ctlistbar control contains a number of useful methods and properties. Before starting an instance study, it is necessary to understand some of its main methods and properties first. Tables I and II list several major methods and properties, along with their types and descriptions. After the initial understanding, we will now begin to explain the case.
(Table i)
| Method |
return type |
Description |
| Addlist |
Integer |
Add a new grouping |
| DeleteList |
Boolean |
Remove an existing group from the control |
| addListItem |
Integer |
Add a new item to a group |
| DeleteItem |
Boolean |
Delete an item in a group |
| Insertlistitem |
Short |
Inserts a new item at a location in a group |
| Clearlists |
void |
Clear all groups and items in a control |
(Table II)
| Property |
Data type |
Description |
| Backimage |
Picture |
Sets the background picture of the control. Using this property, you can achieve the "skin" function. |
| Barheight |
Integer |
Sets the height of the grouping button. |
| Bordertype |
Integer |
To set the border style of a control |
| BorderColor |
Long |
Sets the border color of the control, which is valid only if Bordertype is set to "0-regular." |
| Buttonbackcolor |
Long |
Sets the color of group buttons and up and down scrolling buttons. |
| Buttonforecolor |
Long |
Sets the font color for group buttons and up and down scrolling buttons. |
| Buttonsize |
Integer |
Sets the up and down scroll button size. |
| GradientFill |
Boolean |
Sets whether the control background shows gradients. |
| Gradcolorfrom |
Long |
Sets the starting color for gradients. |
| Gradcolorto |
Long |
Sets the end color for gradients. |
| Iconsize |
Integer |
The Set icon display mode is a large or small icon. |
| Image1-6 |
Picture |
Sets up 6 pictures that are loaded beforehand in the control. |
| Listbarstyle |
Integer |
Sets the control portrait or landscape display. |
| Listbackcolor |
Long |
Sets the background color of the control. |
| Listforecolor |
Long |
Sets the color of item text in a group. |
| Listscrollspeed |
Integer |
Sets the speed at which items are scrolled. |
| Itemscrollspeed |
Integer |
Sets the speed at which grouping slides. |
Step one: Start Visual Basic 6.0 first, create a new window, and modify the Caption property of the window for your favorite name, such as "My QQ menu".
Step two: Load the Ctlistbar control and set its properties.
① Right-click in the Control toolbar, select "Part", click "Browse" in the pop-up window, locate the Ctlistbar control, load it, add it to the Form1 form, and drag the mouse to resize it.
② Modify the Caption property to "my buddy." The Caption property value will be the name of the first group in the menu.
③ Modify the Listbackcolor property. In the example, we borrowed the picture of QQ, set the property value to &h00808000&, the background color and picture background match.
④ loads the picture in the images property. The Ctlistbar control itself can load 6 pictures, where we load 6 pictures from the head of QQ (Figure 1).
⑤ the remaining properties can be referenced in table 2, set according to your own preferences. Here we use the default values.
Tip: Although the Ctlistbar control can only load 6 pictures, there are other ways to make the Ctlistbar control use more pictures, such as using PictureBox controls, ImageList controls, and so on.
Step three: Add other controls to complete the setup of the interface.
Add 5 CommandButton to the form, set the name to Cmd_addlist, Cmd_dellist, Cmd_additem, Cmd_delitem, Cmd_insert, and then set the Caption property to add Group , delete group, add item, delete item, insert item.
Here, the interface settings are fixed, finished as shown in Figure 2.
Fourth step: Next, we begin to write code to achieve specific functions.
① declares 4 global variables.
Dim strListName, strItemName As String
Dim intListNum, intItemNum As Integer
②ctlistbar controls cannot be preconfigured with groups and items and can only be added dynamically, so we add code to the Form_Load () event, adding result groupings and items.
ctListBar1.AddList "陌生人"
ctListBar1.AddList "黑名单"
ctListBar1.AddListItem 1, "My heart", ctListBar1.Image1
ctListBar1.AddListItem 1, "第七乐章", ctListBar1.Image2
ctListBar1.AddListItem 1, "小A", ctListBar1.Image3
ctListBar1.AddListItem 1, "小B", ctListBar1.Image4
ctListBar1.AddListItem 1, "张三", ctListBar1.Image5
ctListBar1.AddListItem 1, "李四", ctListBar1.Image6
In the code above, we've added the new "Stranger" and "blacklist" two groupings, and added 6 items to the previously set of my friends group.
Tip: The Ctlistbar1.addlistitem method uses 3 parameters, the nindex (the index of the group), the StrText (the name of the item), the picture of the project.
③ Enter code in the Click event of the button control Cmd_addlist:
strListName = ""
strListName = InputBox("请输入要添加的分组名称", "添加分组")
If strListName <> "" Then ctListBar1.AddList strListName
Enter the code in the Click event of the button control Cmd_dellist:
intListNum = 0
intListNum = Val(InputBox("请输入要删除的分组标识号", "删除分组"))
If intListNum <> 0 Then ctListBar1.DeleteList intListNum
Enter the code in the Click event of the button control Cmd_additem:
strItemName = ""
intListNum = 0
intListNum = Val(InputBox("请输入要添加的项目所在分组的标识号", "添加项目"))
If intListNum <> 0 Then strItemName = InputBox("请输入要添加的项目的名称", "添加项目")
If strItemName <> "" Then ctListBar1.AddListItem intListNum, strItemName, ctListBar1.Image1
Enter the code in the Click event of the button control Cmd_delitem:
intListNum = 0
intItemNum = 0
intListNum = Val(InputBox("请输入要删除的项目所在分组的标识号", "删除项目"))
If intListNum <> 0 Then intItemNum = Val(InputBox("请输入要删除的项目的标识号", "删除项目"))
If intItemNum <> 0 Then ctListBar1.DeleteItem intListNum, intItemNum
Enter the code in the Click event of the button control Cmd_insert:
intListNum = 0
intItemNum = 0
strItemName = ""
intListNum = Val(InputBox("请输入要插入的项目所在分组的标识号", "插入项目"))
If intListNum <> 0 Then intItemNum = Val(InputBox("请输入要插入的项目所在位置的标识号", "插入项目"))
If intItemNum <> 0 Then strItemName = InputBox("请输入要插入的项目的名称", "插入项目")
If strItemName <> "" Then ctListBar1.InsertListItem intListNum, intItemNum, strItemName, tListBar1.Image1
Tip: Items added with addListItem can only be added at the end of the group, and the Insertlistitem method inserts a new item at the specified position in a group.
Here, this simple instance program is complete, press F5, see the effect (Figure 3), is it cool? And QQ like a pole! The Ctlistbar control is useful and can be used to replace the traditional menus edited by the menu editor in Visual Basic, and many well-known software uses similar menu effects. Use this control in your program, and you'll be able to brighten up your program.