Using VB.NET Active MDI Form Controls: Part 2

In this Article You will learn how to impliment pest procdure in Mdi Child Form.
  • 2952

Introduction

AS my previous article helps you to learn Create procedure for coping text from RichTextBox To Clipboard. Now I am going to tell about the working of Pest controls by which you can Pest your Clipboard Copied text into MDI Child form RichTextBox.   

Get to Work

With the help of below given example, you can learn how to create an procedure that Pest your copied text to the RichTextBox using the click event of the Pest menu control. Here are the step required to build an procedure to pest text from Clipboard to MDI child form RichTextBox.

Step to Create and Implement MDI Child Form

  1. Assumes there is an MDI parent form having MenuStrip with option New, Window and Close in New menu, main form contain one Child form having a RichTexBox. For Details, see Creating an MDI Form.
     
    5.gif

  2. Add one More control in Main form MenuStrip As Pest under Edit Menu.

      6.gif
     

  3. Double click on Pest control and write this Code.

       Public Sub mniPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mniPaste.Click

       ' Determine the active child form.
       Dim activeChild As Form = Me.ParentForm.ActiveMDIChild
           
       ' If there is an active child form, find the active control, which
       ' in this example should be a RichTextBox.
       If (Not activeChild Is Nothing) Then
          Try
             Dim theBox As RichTextBox = Ctype(activeChild.ActiveControl, RichTextBox)
             If (Not theBox Is Nothing) Then
                ' Create a new instance of the DataObject interface.
                Dim data As IDataObject = Clipboard.GetDataObject()
                ' If the data is text, then set the text of the
                ' RichTextBox to the text in the clipboard.
                If (data.GetDataPresent(DataFormats.Text)) Then
                   theBox.SelectedText = data.GetData(DataFormats.Text).ToString()
                End If
             End If
          Catch
             MessageBox.Show("You need to select a RichTextBox.")
          End Try
       End If
    End Sub

     

  4. Debug the application and click on New button a MDI Child form with RichTextBox will open. Now by using Pest control in the Edit Menu you can pest your copied text into the RichTextBox. 

      7.gif

Summary

In this article, we discussed how to Create a procedure which helps to pest the text from clipboard to MDI Child form RichTextBox using Visual Studio 2010 and VB.NET.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.