![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Then, at runtime:
Here is some example code both to set up the TabStrip when the form loads and to respond to clicks. Assume that the TabStrip is named TabStrip1, the array of Frame controls is called Frame1, and the global variable for keeping track of the current Tab is called CurrentTab: Private Sub Form_Load() Dim i As Integer Move all frames to fill client area. Set Visible to False and BorderStyle to None for all. For i = 0 To Frame1.Count - 1 With Frame1(i) .Move TabStrip1.ClientLeft, _ TabStrip1.ClientTop, _ TabStrip1.ClientWidth, _ TabStrip1.ClientHeight .Visible = False .BorderStyle = 0 End With Next i Make Tab 1 active and its Frame visible. CurrentTab = 1 Set TabStrip1.SelectedItem = TabStrip1.Tabs(CurrentTab) Frame1(CurrentTab - 1).Visible = True End Sub Private Sub TabStrip1_Click() If TabStrip1.SelectedItem.Index = CurrentTab _ Then Exit Sub Frame1(TabStrip1.SelectedItem.Index - 1).Visible _ = True Frame1(CurrentTab - 1).Visible = False CurrentTab = TabStrip1.SelectedItem.Index End Sub At runtime, you should have the Frame controls display without a border or caption. This can be done by setting the BorderStyle property to None. At design time, however, seeing the Frame and its caption is useful, so you might want to consider leaving the BorderStyle property at Fixed Single during program design and then setting it to None in code at runtime, as was done in the previous sample code. During design, how do you work with a stack of Frame controls that are by necessity overlapping each other? The trick is to use the Order command on the Format menu. Use Bring to Front to put a Frame on top of the stack, so you can add controls to it and arrange them. Use Send to Back to move the current Frame to the bottom of the stack, so you can work on another Frame. ListView ControlThe ListView control permits you to display lists of items. Ill bet you are already familiar with this control. Just look at Windows Explorer; the right panel in the Explorer window is a ListView control (this is, after all, why they are called Windows Common Controlsthey are used in many different Windows applications). Four types of views are available in a ListView control:
You can get a feel for what these views are like by opening Windows Explorer and using the commands on its View menu to try out the different views. When a ListView control is in Icon view, you can use the mouse to drag items around, rearranging them within the control as desired. Drag-and-drop is also operative, if it is enabled. SmallIcon view offers similar rearranging capabilities, but the items are displayed in list format with small icons rather than as large icons. List view appears similar to SmallIcon view, except that you cannot rearrange items, and the list is, by default, sorted. Report view offers the option of two or more columns in the list, permitting you to display additional details about each item. For example, in Windows Explorer, Report view (called Details) displays not only the file name but also its size, creation date, and so on. As is the case with the other controls we have been discussing, the ListView control uses collections. Each item displayed in the control is a ListItem object; all of these objects are within the controls ListItems collection. This control uses one other collection, as we will soon see. Each ListView control can have two ImageList controls associated with it. The ImageList controls are used to store the icons that will be used in Icon and SmallIcon views. You can specify the ImageList controls at design time using the ListView controls property pages, or you can set them at runtime: ListView1.Icons = ImageList1 ListView1.SmallIcons = ImageList2 Adding items to the ListView control is done with (of course) the ListItems collections Add method. Heres the syntax: ListView1.ListItems.Add index, key, text, icon, smallIcon index and key are the same as for all the other collections we have seenthe numerical position of the new item in the collection and a unique identifying string. Text is the data to be displayed. The final two argumentsicon and smallIconidentify the icons to be displayed with the item in Icon and SmallIcon views, respectively. These images are taken from the ImageList control or controls that were associated with the ListView control, as described earlier. You can specify an image using either its Index property or its Key property in the ImageList control. Here is how you would add a new item to a ListView control, at the next available Index position, specifying an icon by Index and a smallIcon by Key: ListView1.ListItems.Add , apricot, Apricot, 2, fruit
|
![]() |