It looks like you need to use something lower than C # if you want to override the default copy / paste behavior (see C # clipboard event and Detecting and differentiating clipboard events (cut, copy and paste) ). However, perhaps you could put your logic in a “defender” that knows how to send a request for an action (for example, “Copy”), and then redirect it as appropriate.
Here is an example class:
namespace Your.App
{
public class GuardedCommand
{
public bool CurrentlyEditing { get; set; }
public GuardedCommand()
{
CurrentlyEditing = false;
}
public void DoCopy()
{
if(CurrentlyEditing)
StandardCopyCommand();
else
ShortcutCopyCommand();
}
void ShortcutCopyCommand() { }
void StandardCopyCommand() { }
}
}
, guardedCommand.CurrentlyEditing BeforeLabelEdit AfterLabelEdit. , CTRL + C, guardedCommand.DoCopy(), .
, , State Pattern, . ( ), , DoCopy() DoPaste(), if/else switch. , CurrentlyEditing , , DoCopy().
, , , , - :
namespace Your.App
{
interface IClipboard
{
void Copy();
void Paste();
}
class MyCustomClipboard : IClipboard
{
public void Copy() { }
public void Paste() { }
}
class DefaultClipboard : IClipboard
{
public void Copy() { }
public void Paste() { }
}
public class StateClass
{
IClipboard State { get; set; }
public StateClass()
{
CurrentlyEditing = false;
}
bool _currentlyEditing;
public bool CurrentlyEditing
{
get { return _currentlyEditing; }
set
{
_currentlyEditing = value;
if(_currentlyEditing)
State = new DefaultClipboard();
else
State = new MyCustomClipboard();
}
}
public void Copy()
{
State.Copy();
}
public void Paste()
{
State.Paste();
}
}
}
, , ( , , ).