home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / listbox.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  4.7 KB  |  138 lines

  1. VERSION 4.00
  2. Begin VB.Form frmListBox 
  3.    Caption         =   "List Box Example"
  4.    ClientHeight    =   5310
  5.    ClientLeft      =   1230
  6.    ClientTop       =   1695
  7.    ClientWidth     =   5655
  8.    BeginProperty Font 
  9.       name            =   "MS Sans Serif"
  10.       charset         =   1
  11.       weight          =   700
  12.       size            =   8.25
  13.       underline       =   0   'False
  14.       italic          =   0   'False
  15.       strikethrough   =   0   'False
  16.    EndProperty
  17.    Height          =   5715
  18.    Left            =   1170
  19.    LinkTopic       =   "Form1"
  20.    ScaleHeight     =   5310
  21.    ScaleWidth      =   5655
  22.    Top             =   1350
  23.    Width           =   5775
  24.    Begin VB.CommandButton cmdClose 
  25.       Caption         =   "&Close"
  26.       Height          =   495
  27.       Left            =   3840
  28.       TabIndex        =   8
  29.       Top             =   3840
  30.       Width           =   1215
  31.    End
  32.    Begin VB.CommandButton cmdClear 
  33.       Caption         =   "C&lear"
  34.       Height          =   495
  35.       Left            =   3840
  36.       TabIndex        =   7
  37.       Top             =   2520
  38.       Width           =   1215
  39.    End
  40.    Begin VB.CommandButton cmdRemove 
  41.       Caption         =   "&Remove"
  42.       Enabled         =   0   'False
  43.       Height          =   495
  44.       Left            =   3840
  45.       TabIndex        =   6
  46.       Top             =   1680
  47.       Width           =   1215
  48.    End
  49.    Begin VB.CommandButton cmdAdd 
  50.       Caption         =   "&Add"
  51.       Default         =   -1  'True
  52.       Enabled         =   0   'False
  53.       Height          =   495
  54.       Left            =   3840
  55.       TabIndex        =   5
  56.       Top             =   840
  57.       Width           =   1215
  58.    End
  59.    Begin VB.ListBox lstClient 
  60.       Height          =   2760
  61.       Left            =   600
  62.       Sorted          =   -1  'True
  63.       TabIndex        =   1
  64.       Top             =   1440
  65.       Width           =   2655
  66.    End
  67.    Begin VB.TextBox txtName 
  68.       Height          =   375
  69.       Left            =   600
  70.       TabIndex        =   0
  71.       Top             =   720
  72.       Width           =   2655
  73.    End
  74.    Begin VB.Label lblDisplay 
  75.       BorderStyle     =   1  'Fixed Single
  76.       Height          =   375
  77.       Left            =   2415
  78.       TabIndex        =   4
  79.       Top             =   4440
  80.       Width           =   855
  81.    End
  82.    Begin VB.Label lblClients 
  83.       Caption         =   "# Clients"
  84.       Height          =   255
  85.       Left            =   600
  86.       TabIndex        =   3
  87.       Top             =   4440
  88.       Width           =   855
  89.    End
  90.    Begin VB.Label lblName 
  91.       Caption         =   "&Name to add"
  92.       Height          =   255
  93.       Left            =   600
  94.       TabIndex        =   2
  95.       Top             =   360
  96.       Width           =   1215
  97.    End
  98. Attribute VB_Name = "frmListBox"
  99. Attribute VB_Creatable = False
  100. Attribute VB_Exposed = False
  101. Private Sub cmdAdd_Click()
  102.     lstClient.AddItem txtName.Text                  ' Add a client name to the list box.
  103.     txtName.Text = ""                               ' Clear the text box.
  104.     txtName.SetFocus                                ' Place focus back to the text box.
  105.     lblDisplay.Caption = lstClient.ListCount        ' Display the number of items in the list box.
  106. End Sub
  107. Private Sub cmdClear_Click()
  108.     lstClient.Clear                                 ' Empty the list box.
  109.     cmdRemove.Enabled = False                       ' Disable the Remove button.
  110.     lblDisplay.Caption = lstClient.ListCount        ' Display the number of items in the list box.
  111. End Sub
  112. Private Sub cmdClose_Click()
  113.     Unload Me   ' Unload this form.
  114. End Sub
  115. Private Sub cmdRemove_Click()
  116. Dim Ind As Integer
  117.     Ind = lstClient.ListIndex                       ' Get index.
  118.     If Ind >= 0 Then                                ' Make sure a list item is selected.
  119.         lstClient.RemoveItem Ind                    ' Remove the item from the list box.
  120.         lblDisplay.Caption = lstClient.ListCount    ' Display the number of items in the list box.
  121.     Else
  122.         Beep                                        ' This should never occur, because Remove is always disabled if no entry is selected.
  123.     End If
  124.     ' Disable the Remove button if no entries are selected in the list box.
  125.     cmdRemove.Enabled = (lstClient.ListIndex <> -1)
  126. End Sub
  127. Private Sub lstClient_Click()
  128.     cmdRemove.Enabled = (lstClient.ListIndex <> -1)
  129. End Sub
  130. Private Sub lstClient_DblClick()
  131.     ' A user clicked the Remove button.
  132.     cmdRemove.Value = True
  133. End Sub
  134. Private Sub txtName_Change()
  135.     ' Enable the Add button if at least one character in the name is entered or changed.
  136.     cmdAdd.Enabled = (Len(txtName.Text) > 0)
  137. End Sub
  138.