Solved

Implement undo, cut, paste, copy functionality

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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