Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Working With Active MDI Child Form Controls: Part 2
WhatsApp
Manish Tewatia
14y
18.7k
0
0
100
Article
Working With Pest Control.zip
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
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
.
Add one More control in Main form MenuStrip As Pest under Edit Menu.
Double click on Pest control and write this Code.
private
void
pestToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
// Determine the active child form.
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
)
{
// Create a new instance of the DataObject interface.
IDataObject
data =
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
))
{
theBox.SelectedText = data.GetData(
DataFormats
.Text).ToString
();
}
}
}
catch
{
MessageBox
.Show
(
"You need to select a RichTextBox."
);
}
}
}
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.
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 C#.
C#
MDI Controls
Pest Control
Up Next
Ebook Download
View all
GitHub Copilot - Coding with Copilot
Read by 2.7k people
Download Now!
Learn
View all
Membership not found