home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / code_gen / vbcodwiz / vbcwur.exe / VBCWUR.ZIP / VBCODE.DB_ / VBCODE.DB
Encoding:
INI File  |  1995-05-01  |  5.2 KB  |  188 lines

  1. [1]
  2. CenterForm centers the form passed to it horizontally and vertically on the screen. 
  3. [Code]
  4. Sub CenterForm (F As Form)
  5. F.Left = (Screen.Width - F.Width) / 2
  6. F.Top = (Screen.Height - F.Height) / 2
  7. End Sub
  8. [Stop]
  9. [2]
  10.  
  11.  
  12. [Code]
  13. 'Declares for DblClick
  14. DblClick Event Example
  15. The example displays a selected list item in a text box when either a command button is clicked or 
  16. a list item is double-clicked.  To try this example, paste the code into the Declarations section of a 
  17. form that contains list box, a text box and a command button.  Then press F5 and click the 
  18. command button or double click a list box item.
  19.  
  20. Sub Form_Load ()
  21.     List1.AddItem "John"    ' Add list box entries.
  22.     List1.AddItem "Paul"
  23.     List1.AddItem "George"
  24.     List1.AddItem "Ringo"
  25. End Sub
  26.  
  27.  
  28.  
  29. Sub List1_DblClick ()
  30.     Command1.Value = True    ' Trigger Click event.
  31. End Sub
  32.  
  33.  
  34.  
  35. Sub Command1_Click ()
  36.     Text1.Text = List1.Text    ' Display selection.
  37. End Sub
  38.  
  39.  
  40.  
  41. [Stop]
  42. [3]
  43.  
  44.  
  45. [Code]
  46. 'Declares for DrawMode Property Example
  47. DrawMode Property Example
  48. The example enables drawing on a form by dragging the mouse pointer.  Each mouse click sets a 
  49. different draw mode.  To try this example, paste the code into the Declarations section of a form.  
  50. Then press F5 and click the form.
  51.  
  52. Sub Form_Load
  53.     DrawWidth = 10                    ' Set DrawWidth.
  54. End Sub
  55. Sub Form_Click ()
  56.     Static M As Integer                ' Current DrawMode setting.
  57.     ForeColor = QBColor(Int(Rnd * 15))    ' Choose a color.
  58.     M = ((M + 1) Mod 16) + 1            ' Keep DrawMode 16 or less.
  59.     DrawMode = M                        ' Set DrawMode.
  60. End Sub
  61. Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  62.     If Button Then                    ' While the button is pressed,
  63.         PSet (X, Y)                        ' draw a big point.
  64.     End If
  65. End Sub
  66.  
  67.  
  68.  
  69. [Stop]
  70. [4]
  71.  
  72.  
  73. [Code]
  74. 'Declares for Enabled Property
  75. Enabled Property Example
  76. The example enables a command button whenever the text box contains text.  To try this example, 
  77. paste the code into the Declarations section of a form.  Then press F5 and type something into the 
  78. text box.
  79.  
  80. Sub Form_Load ()
  81.     Text1.Text = ""        ' Clear the text box.
  82.     Command1.Caption = "Save"    ' Put caption on button.
  83. End Sub
  84. Sub Text1_Change ()
  85.     If Text1.Text = "" Then    ' See if textbox is empty.
  86.         Command1.Enabled = False    ' Disable button.
  87.     Else
  88.         Command1.Enabled = True    ' Enable button.
  89.     End If
  90. End Sub
  91.  
  92.  
  93.  
  94. [Stop]
  95. [5]
  96.  
  97.  
  98. [Code]
  99. 'Declares for ActiveForm, ActiveControl Properties Example 2
  100. ActiveForm, ActiveControl Properties Example 2
  101. The example shows how you can use the Clipboard in cut, copy, paste, and delete operations 
  102. using buttons on a toolbar.  To try this example, draw a text box and a check box on Form1, then 
  103. create a new MDI form.  On the MDI form, draw a picture box and then draw a command button in 
  104. the picture box.  Set the Index property on the command button to 0 (this creates a control array).  
  105. On Form1, set the MDIChild property to True.
  106. To run the example, copy the code into the Declarations section of the MDI form and press F5.  
  107. Notice that if the check box has the focus, the buttons don't work.
  108.  
  109. Sub MDIForm_Load ()
  110.     Dim I                        ' Declare variable.
  111.     Command1(0).Move 0, 0, 700, 300    ' Position button on toolbar.
  112.     For I = 1 To 3    ' Create other buttons.
  113.         Load Command1(I)    ' Create button.
  114.         Command1(I).Move I * 700, 0, 700, 300    ' Place and size button.
  115.         Command1(I).Visible = True    ' Display button.
  116.     Next I
  117.     Command1(0).Caption = "Cut"    ' Set button captions.
  118.     Command1(1).Caption = "Copy"
  119.     Command1(2).Caption = "Paste"
  120.     Command1(3).Caption = "Del"
  121. End Sub
  122.  
  123. Sub Command1_Click (Index As Integer)
  124.     ' ActiveForm refers to the active form in the MDI form.
  125.     If TypeOf ActiveForm.ActiveControl Is TextBox Then
  126.         Select Case Index
  127.             Case 0            ' Cut.
  128.                 ' Copy selected text to Clipboard.
  129.                 Clipboard.SetText ActiveForm.ActiveControl.SelText
  130.                 ' Delete selected text.
  131.                 ActiveForm.ActiveControl.SelText = ""
  132.             Case 1            ' Copy.
  133.                 ' Copy selected text to Clipboard.
  134.                 Clipboard.SetText ActiveForm.ActiveControl.SelText
  135.             Case 2            ' Paste.
  136.                 ' Put Clipboard text in text box.
  137.                 ActiveForm.ActiveControl.SelText = Clipboard.GetText()
  138.             Case 3            ' Delete.
  139.                 ' Delete selected text.
  140.                 ActiveForm.ActiveControl.SelText = ""
  141.         End Select
  142.     End If
  143. End Sub
  144.  
  145.  
  146.  
  147. [Stop]
  148. [6]
  149. 'Declares for Click Event Example
  150. Click Event Example
  151. In this example, each time a picture box is clicked it moves diagonally across a form.  To try this 
  152. example, paste the code into the Declarations section of a form that contains a picture box positioned 
  153. at the lower left corner of the form.  Then press F5 and click the picture box.
  154.  
  155.  
  156.  
  157. [Code]
  158. Sub Picture1_Click ()
  159.    Picture1.Move Picture1.Left + 750, Picture1.Top - 550
  160. End Sub
  161.  
  162.  
  163.  
  164.  
  165.  
  166. [Stop]
  167. [7]
  168. Caption Property Example
  169.  
  170. The example changes the caption on a command button each time the user clicks the button.  To try 
  171. this example, paste the code into the Declarations section of a form containing a command button 
  172. named Command1.  Then press F5 and click the button.
  173.  
  174. [Code]
  175. 'Declares for caption example
  176. Sub Command1_Click ()
  177.     ' Check caption, then change it.
  178.     If Command1.Caption = "Clicked" Then
  179.         Command1.Caption = "OK"
  180.     Else
  181.         Command1.Caption = "Clicked"
  182.     End If
  183. End Sub
  184.  
  185.  
  186.  
  187. [Stop]
  188.