home *** CD-ROM | disk | FTP | other *** search
/ distrib.akp.su/Programming/Vb-6+Rus/ / distrib.akp.su.tar / distrib.akp.su / Programming / Vb-6+Rus / VB98 / TEMPLATE / CONTROLS / LISTBTNS.FRM (.txt) next >
Visual Basic Form  |  1998-06-18  |  5KB  |  154 lines

  1. VERSION 5.00
  2. Begin VB.Form frmListButtons 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   3405
  5.    ClientLeft      =   2880
  6.    ClientTop       =   3210
  7.    ClientWidth     =   3330
  8.    LinkTopic       =   "Form1"
  9.    LockControls    =   -1  'True
  10.    ScaleHeight     =   3405
  11.    ScaleWidth      =   3330
  12.    Begin VB.ListBox lstItems 
  13.       DragIcon        =   "Button ListBox.frx":0000
  14.       Height          =   2895
  15.       IntegralHeight  =   0   'False
  16.       Left            =   450
  17.       TabIndex        =   4
  18.       Top             =   165
  19.       Width           =   2280
  20.    End
  21.    Begin VB.CommandButton cmdUp 
  22.       Enabled         =   0   'False
  23.       Height          =   330
  24.       Left            =   2790
  25.       Picture         =   "Button ListBox.frx":0442
  26.       Style           =   1  'Graphical
  27.       TabIndex        =   3
  28.       ToolTipText     =   "5011"
  29.       Top             =   1215
  30.       UseMaskColor    =   -1  'True
  31.       Width           =   330
  32.    End
  33.    Begin VB.CommandButton cmdDown 
  34.       Enabled         =   0   'False
  35.       Height          =   330
  36.       Left            =   2790
  37.       Picture         =   "Button ListBox.frx":0544
  38.       Style           =   1  'Graphical
  39.       TabIndex        =   2
  40.       ToolTipText     =   "5012"
  41.       Top             =   1695
  42.       UseMaskColor    =   -1  'True
  43.       Width           =   330
  44.    End
  45.    Begin VB.CommandButton cmdDelete 
  46.       Enabled         =   0   'False
  47.       Height          =   330
  48.       Left            =   2790
  49.       Picture         =   "Button ListBox.frx":0646
  50.       Style           =   1  'Graphical
  51.       TabIndex        =   1
  52.       ToolTipText     =   "5010"
  53.       Top             =   735
  54.       UseMaskColor    =   -1  'True
  55.       Width           =   330
  56.    End
  57.    Begin VB.CommandButton cmdAdd 
  58.       Height          =   330
  59.       Left            =   2790
  60.       Picture         =   "Button ListBox.frx":0748
  61.       Style           =   1  'Graphical
  62.       TabIndex        =   0
  63.       ToolTipText     =   "5009"
  64.       Top             =   255
  65.       UseMaskColor    =   -1  'True
  66.       Width           =   330
  67.    End
  68. Attribute VB_Name = "frmListButtons"
  69. Attribute VB_GlobalNameSpace = False
  70. Attribute VB_Creatable = False
  71. Attribute VB_PredeclaredId = True
  72. Attribute VB_Exposed = False
  73. Private Sub cmdAdd_Click()
  74.   Dim sTmp As String
  75.   sTmp = InputBox("Enter new item to add:")
  76.   If Len(sTmp) = 0 Then Exit Sub
  77.   lstItems.AddItem sTmp
  78. End Sub
  79. Private Sub cmdDelete_Click()
  80.   If lstItems.ListIndex > -1 Then
  81.     If MsgBox("Delete '" & lstItems.Text & "'?", vbQuestion + vbYesNo) = vbYes Then
  82.       lstItems.RemoveItem lstItems.ListIndex
  83.     End If
  84.   End If
  85. End Sub
  86. Private Sub cmdUp_Click()
  87.   On Error Resume Next
  88.   Dim nItem As Integer
  89.   With lstItems
  90.     If .ListIndex < 0 Then Exit Sub
  91.     nItem = .ListIndex
  92.     If nItem = 0 Then Exit Sub  'can't move 1st item up
  93.     'move item up
  94.     .AddItem .Text, nItem - 1
  95.     'remove old item
  96.     .RemoveItem nItem + 1
  97.     'select the item that was just moved
  98.     .Selected(nItem - 1) = True
  99.   End With
  100. End Sub
  101. Private Sub cmdDown_Click()
  102.   On Error Resume Next
  103.   Dim nItem As Integer
  104.   With lstItems
  105.     If .ListIndex < 0 Then Exit Sub
  106.     nItem = .ListIndex
  107.     If nItem = .ListCount - 1 Then Exit Sub 'can't move last item down
  108.     'move item down
  109.     .AddItem .Text, nItem + 2
  110.     'remove old item
  111.     .RemoveItem nItem
  112.     'select the item that was just moved
  113.     .Selected(nItem + 1) = True
  114.   End With
  115. End Sub
  116. Private Sub lstItems_DragDrop(Source As Control, X As Single, Y As Single)
  117.   Dim i As Integer
  118.   Dim nID As Integer
  119.   Dim sTmp As String
  120.   If Source.Name <> "lstItems" Then Exit Sub
  121.   If lstItems.ListCount = 0 Then Exit Sub
  122.   With lstItems
  123.     i = (Y \ TextHeight("A")) + .TopIndex
  124.     If i = .ListIndex Then
  125.       'dropped on top of itself
  126.       Exit Sub
  127.     End If
  128.     If i > .ListCount - 1 Then i = .ListCount - 1
  129.     nID = .ListIndex
  130.     sTmp = .Text
  131.     If (nID > -1) Then
  132.       sTmp = .Text
  133.       .RemoveItem nID
  134.       .AddItem sTmp, i
  135.       .ListIndex = .NewIndex
  136.     End If
  137.   End With
  138.   SetListButtons
  139. End Sub
  140. Sub lstItems_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  141.   If Button = vbLeftButton Then lstItems.Drag
  142. End Sub
  143. Private Sub lstItems_Click()
  144.   SetListButtons
  145. End Sub
  146. Sub SetListButtons()
  147.   Dim i As Integer
  148.   i = lstItems.ListIndex
  149.   'set the state of the move buttons
  150.   cmdUp.Enabled = (i > 0)
  151.   cmdDown.Enabled = ((i > -1) And (i < (lstItems.ListCount - 1)))
  152.   cmdDelete.Enabled = (i > -1)
  153. End Sub
  154.