Visual Basic Reference
This example prints the time on the active child form in an MDIForm object. To try this example, create an MDIForm, draw a PictureBox control on it and a CommandButton control in the PictureBox. In Form1, set the MDIChild property to True. (You can also set AutoRedraw to True to keep text on the form even after covering it with another form.) Paste the appropriate code into the Declarations section of each form, and then press F5.
' Copy all code into the MDI form. Private Sub MDIForm_Load () Dim NewForm As New Form1 ' Create new instance of Form1. NewForm.Show End Sub Private Sub Command1_Click () ' Print the time on the active form. ActiveForm.Print "The time is " & Format(Now, "Long Time") End Sub
This example shows how you can use the Clipboard object in cut, copy, paste, and delete operations using buttons on a toolbar. To try this example, create a new project, then put TextBox and CheckBox controls on Form1, and then create a new MDI form. On the MDI form, place a PictureBox control, and then insert a CommandButton control in the PictureBox. Set the Index property of the CommandButton to 0 (creating a control array). Set the MDIChild property of Form1 to True.
To run the example, copy the code into the Declarations section of the MDIForm, and then press F5. Notice that when the CheckBox has the focus, the buttons don't work, since the CheckBox is now the active control instead of the TextBox.
Private 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 Private 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