?
Solved

Implement undo, cut, paste, copy functionality

Posted on 2003-11-25
3
Medium Priority
?
445 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 1000 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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

752 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