SIGN UP MEMBER LOGIN:    
ARTICLE

Working With Active MDI Child Form Controls

Posted by Manish Tewatia Articles | Windows Forms C# July 13, 2010
In this Article You can learn How to determine a Active MDI Child form and Working with its controls.
Reader Level:
 

Introduction

AS my previous article helps you to learn MDI Form and Child Form Creation. Now I am going to tell about the working of controls which has focus on the currently active child form.   

Get to Work

With the help of below given example, you can learn how to create an procedure that copies selected text to the clipboard using the click event of the copy menu control. Here are the step required to build an procedure to copy selected text from the child form text box.

To Create a procedure on active form or giving a specific instance of the recently active child form you can use ActiveMdiChild property. Same as to specify the active control of the form on which procedure works you have use ActiveControl property.

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.

    1.gif
     

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

     1.1.gif
     

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

    private void copyToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Form activeChild = this.ActiveMdiChild;
        // If there is an active child form, find the active control, which
        // in this example should be a RichTextBox.
        if (activeChild != null)
        {
            try
            {
                RichTextBox theBox = (RichTextBox)activeChild.ActiveControl;
                if (theBox != null)
                {
                    // Put the selected text on the Clipboard.
                    Clipboard.SetDataObject(theBox.SelectedText);
                }
            }
            catch
            {
                MessageBox.Show("You need to select a RichTextBox.");
            }
        }
    }
     

  4. Debug the application and click on New button a MDI Child form with RichTextBox will open. Now you write anything in text box and select them now go to Copy control in Edit Menu and Click on it. Your text was copied you can past the text from your clipboard.

     1.3.gif

Summary

In this article, we discussed how to Create a procedure which helps to copy selected text from the active child form to clipboard using Visual Studio 2010 and C#.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor