Solved

Implement undo, cut, paste, copy functionality

Posted on 2003-11-25
3
444 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 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