Solved

Implement undo, cut, paste, copy functionality

Posted on 2003-11-25
3
405 Views
Last Modified: 2011-10-03
How can I implement cut paste copy and undo functionality in my text boxes?  the shortcuts work, crtl-c and what not.  Are they methods I can easily call (how would I know which control had the focus before the menu item was selected)?
0
Comment
Question by:jjacksn
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 250 total points
ID: 9823309
You have the methods TextBox.Copy, TextBox.Cut, TextBox.Paste and TextBox.Undo. Using them you can make all the things you asked for.

To find out which control has the focus, you can do this:

private Control FindFocused (Control parent) {
  foreach (Control ctrl in parent.Controls)
    if (ctrl.ContainsFocus)  // The focus is on this control or one of it's children
      if (ctrl.Focused)  // This control is focused
        return ctrl;
      else  // A child of this control is focused
        return FindFocused (ctrl);
  return null;  // No focus at all in this control
}

and then in your form call:

Control ctrl = FindFocus (this);
if (ctrl is TextBox) {
  TextBox tBox = (TextBox)ctrl;
  tBox.Copy();
  ....
}
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9826864
Does a control retain the focus even when the menu item is clicked?
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9826876
An interesting question... Try executing the code I gave you in the menu handler. If it returns null, then not, otherwise yes
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now