home *** CD-ROM | disk | FTP | other *** search
INI File | 1995-05-01 | 5.2 KB | 188 lines |
- [1]
- CenterForm centers the form passed to it horizontally and vertically on the screen.
- [Code]
- Sub CenterForm (F As Form)
- F.Left = (Screen.Width - F.Width) / 2
- F.Top = (Screen.Height - F.Height) / 2
- End Sub
- [Stop]
- [2]
-
-
- [Code]
- 'Declares for DblClick
- DblClick Event Example
- The example displays a selected list item in a text box when either a command button is clicked or
- a list item is double-clicked. To try this example, paste the code into the Declarations section of a
- form that contains list box, a text box and a command button. Then press F5 and click the
- command button or double click a list box item.
-
- Sub Form_Load ()
- List1.AddItem "John" ' Add list box entries.
- List1.AddItem "Paul"
- List1.AddItem "George"
- List1.AddItem "Ringo"
- End Sub
-
-
-
- Sub List1_DblClick ()
- Command1.Value = True ' Trigger Click event.
- End Sub
-
-
-
- Sub Command1_Click ()
- Text1.Text = List1.Text ' Display selection.
- End Sub
-
-
-
- [Stop]
- [3]
-
-
- [Code]
- 'Declares for DrawMode Property Example
- DrawMode Property Example
- The example enables drawing on a form by dragging the mouse pointer. Each mouse click sets a
- different draw mode. To try this example, paste the code into the Declarations section of a form.
- Then press F5 and click the form.
-
- Sub Form_Load
- DrawWidth = 10 ' Set DrawWidth.
- End Sub
- Sub Form_Click ()
- Static M As Integer ' Current DrawMode setting.
- ForeColor = QBColor(Int(Rnd * 15)) ' Choose a color.
- M = ((M + 1) Mod 16) + 1 ' Keep DrawMode 16 or less.
- DrawMode = M ' Set DrawMode.
- End Sub
- Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
- If Button Then ' While the button is pressed,
- PSet (X, Y) ' draw a big point.
- End If
- End Sub
-
-
-
- [Stop]
- [4]
-
-
- [Code]
- 'Declares for Enabled Property
- Enabled Property Example
- The example enables a command button whenever the text box contains text. To try this example,
- paste the code into the Declarations section of a form. Then press F5 and type something into the
- text box.
-
- Sub Form_Load ()
- Text1.Text = "" ' Clear the text box.
- Command1.Caption = "Save" ' Put caption on button.
- End Sub
- Sub Text1_Change ()
- If Text1.Text = "" Then ' See if textbox is empty.
- Command1.Enabled = False ' Disable button.
- Else
- Command1.Enabled = True ' Enable button.
- End If
- End Sub
-
-
-
- [Stop]
- [5]
-
-
- [Code]
- 'Declares for ActiveForm, ActiveControl Properties Example 2
- ActiveForm, ActiveControl Properties Example 2
- The example shows how you can use the Clipboard in cut, copy, paste, and delete operations
- using buttons on a toolbar. To try this example, draw a text box and a check box on Form1, then
- create a new MDI form. On the MDI form, draw a picture box and then draw a command button in
- the picture box. Set the Index property on the command button to 0 (this creates a control array).
- On Form1, set the MDIChild property to True.
- To run the example, copy the code into the Declarations section of the MDI form and press F5.
- Notice that if the check box has the focus, the buttons don't work.
-
- Sub MDIForm_Load ()
- Dim I ' Declare variable.
- Command1(0).Move 0, 0, 700, 300 ' Position button on toolbar.
- For I = 1 To 3 ' Create other buttons.
- Load Command1(I) ' Create button.
- Command1(I).Move I * 700, 0, 700, 300 ' Place and size button.
- Command1(I).Visible = True ' Display button.
- Next I
- Command1(0).Caption = "Cut" ' Set button captions.
- Command1(1).Caption = "Copy"
- Command1(2).Caption = "Paste"
- Command1(3).Caption = "Del"
- End Sub
-
- Sub Command1_Click (Index As Integer)
- ' ActiveForm refers to the active form in the MDI form.
- If TypeOf ActiveForm.ActiveControl Is TextBox Then
- Select Case Index
- Case 0 ' Cut.
- ' Copy selected text to Clipboard.
- Clipboard.SetText ActiveForm.ActiveControl.SelText
- ' Delete selected text.
- ActiveForm.ActiveControl.SelText = ""
- Case 1 ' Copy.
- ' Copy selected text to Clipboard.
- Clipboard.SetText ActiveForm.ActiveControl.SelText
- Case 2 ' Paste.
- ' Put Clipboard text in text box.
- ActiveForm.ActiveControl.SelText = Clipboard.GetText()
- Case 3 ' Delete.
- ' Delete selected text.
- ActiveForm.ActiveControl.SelText = ""
- End Select
- End If
- End Sub
-
-
-
- [Stop]
- [6]
- 'Declares for Click Event Example
- Click Event Example
- In this example, each time a picture box is clicked it moves diagonally across a form. To try this
- example, paste the code into the Declarations section of a form that contains a picture box positioned
- at the lower left corner of the form. Then press F5 and click the picture box.
-
-
-
- [Code]
- Sub Picture1_Click ()
- Picture1.Move Picture1.Left + 750, Picture1.Top - 550
- End Sub
-
-
-
-
-
- [Stop]
- [7]
- Caption Property Example
-
- The example changes the caption on a command button each time the user clicks the button. To try
- this example, paste the code into the Declarations section of a form containing a command button
- named Command1. Then press F5 and click the button.
-
- [Code]
- 'Declares for caption example
- Sub Command1_Click ()
- ' Check caption, then change it.
- If Command1.Caption = "Clicked" Then
- Command1.Caption = "OK"
- Else
- Command1.Caption = "Clicked"
- End If
- End Sub
-
-
-
- [Stop]
-