Solved

Implement undo, cut, paste, copy functionality

Posted on 2003-11-25
3
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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