Solved

Disable Ctrl-A, Ctrl-C

Posted on 2009-05-07
5
553 Views
Last Modified: 2013-11-27
Hello Experts

I need to disable the ability of users to select and copy text in a Rich Text Control using Ctrl-A and Ctrl-C.

How do I go about this?

Many thanks
0
Comment
Question by:jindalee
  • 2
5 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24324840
Set the ShortCutsEnabled property to False.

Wayne
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 24324900
To disable only Ctrl+A and Ctrl+C, you will need to intercept the KeyPresses.....
    Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
 
        If e.Control Then
            If e.KeyCode = Keys.C Or e.KeyCode = Keys.A Then
                e.Handled = True
            End If
        End If
 
    End Sub

Open in new window

0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 24332705

        public bool PreFilterMessage(ref Message m)
        {
            if (m.Msg == WM_KEYDOWN)
            {
                return HandleKeys((Keys)((int)m.WParam) & Keys.KeyCode);
            }
            return false;
        }
        public bool HandleKeys(Keys keycode)
        {
            bool ret = true;
            switch (keycode)
            {
                case Keys.Alt | Keys.F4: this.Close();break;
                case Keys.Alt | Keys.N: MoveInList(Direction.FORWARD); break;
                case Keys.Alt | Keys.B: MoveInList(Direction.BACKWORD); break;
                //.........
                default: ret = false; break;
            }
            return ret;
        }

Open in new window

0
 
LVL 1

Author Closing Comment

by:jindalee
ID: 31578957
Thank you webtubbs. Worked first time.

BTW. It is good to see a moderator remind a contributor that a submission should add value to the question and should also address specifics such as programming language. Too many times you see a question asking for a response in (e.g.) VB.Net only to find loads of answers in some other language.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

821 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