SIGN UP MEMBER LOGIN:    
ARTICLE

Restrict Clipboard Shortcuts in TextBox in Silverlight 3

Posted by Diptimaya Patra Articles | Silverlight with C# March 04, 2010
In this article we will see how we can restrict Clipboard shortcuts such as CTRL+C, CTRL+X, and CTRL+V in Silverlight 3 for TextBox Control.
Reader Level:
Download Files:
 

Introduction

In this article we will see how we can restrict Clipboard shortcuts such as CTRL+C, CTRL+X, and CTRL+V in Silverlight 3 for TextBox Control.

Creating Silverlight Project

Fire up Visual Studio 2008 and create a new Silverlight 3 Project. Name it as RestrictCBShortcutSL3.


RestrictFig1.gif

Let's have one or more TextBoxes that will fulfill our sample application.

RestrictFig2.gif

Now for disabling Clipboard shortcuts such as Ctrl+C, Ctrl+X, and Ctrl+V we need to have Custom TextBox control.

So Create a class as CustomTextBox.cs .


RestrictFig3.gif

Now inherit TextBox class to it.
RestrictFig4.gif

Now we will have a boolean property that will decide whether CTRL key is pressed.
RestrictFig5.gif

To override default shortcuts we need to override the base methods such as OnKeyDown and OnkeyUp.

Add the following override methods.

RestrictFig6.gif
Now go back to the XAML code behind and add the Namespace (Your application's namespace) as follows:


RestrictFig7.gif

After adding the Namespace Change the TextBox Control that you need to restrict the Clipboard shortcuts. In our case we will do it for the About User TextBox.

RestrictFig8.gif
Initialize the IsControlKeyDown property to False.

RestrictFig9.gif
Now we are ready to test our application.


RestrictFig10.gif

Try pressing Ctrl+C/Ctrl+X/Ctrl+V the clipboard shortcuts are handled.

Hope this article helps.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor