Solved

CTRL+A not working for textboxes

Posted on 2008-10-07
6
1,128 Views
Last Modified: 2013-12-17
I've trying creating brand new projects and adding a single textbox and even then the CTRL+A for select all doesn't work, it just makes the beep noise.

Now the confusing part is I actually have one of my open source projects that actually works with CTRL+A and if I copy its textboxes out they'll have it working in other programs, but if I modify them then it fails to work.

I have one program with the CTRL+A working, and it doesn't have any differences in the actual textbox, and if it gets copied out to another form/program it'll be working for that specific textbox in that program as well.

Also, I'm using Visual C# Express 2008.
0
Comment
Question by:krusho
  • 4
  • 2
6 Comments
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 22666157
Just write an event handler for key_down event and put the following code into there:

            if(e.Modifiers == Keys.Control && (e.KeyCode==Keys.A ||e.KeyCode==Keys.A))
            {
                textBox2.SelectAll();
            }
0
 

Author Comment

by:krusho
ID: 22670788
I was hoping to avoid doing it for each individual textbox, since the one program that has it working doesn't have any keydown events being handled.
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 22673090
It means they use magic :)

Check if such a handler was attached in some other way and was not created with designer.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:krusho
ID: 22673819
The confusing part is that the program that has it's 2 textboxes working is the same as the default new project I make. If I copy one of those textboxes into the new program then that box will work until I start modifying it.
0
 

Accepted Solution

by:
krusho earned 0 total points
ID: 22673981
I figured out the solution, as to one one appears to magically work. This is rather dumb though and I don't know why Microsoft would make this matter.

this.textBox1.Multiline = false; // this can use CTRL+A
this.textBox1.Multiline = true; // this cannot use CTRL+A

The reason I was being confused is because I failed to realize that working textBox was not multiline, and that the other textBox on that form was actually a RichTextBox

this.richTextBox1.Multiline = false; // this can use CTRL+A
this.richTextBox1.Multiline = true; // this can use CTRL+A
0
 

Author Comment

by:krusho
ID: 22674043
Also, this is another work around since you may still want to use a multiline textbox:

namespace MyTextBoxDemo
{
    public class MyTextBox : System.Windows.Forms.TextBox
    {
        protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
        {
            if (e.Control && (e.KeyCode == System.Windows.Forms.Keys.A))
            {
                this.SelectAll();
                e.SuppressKeyPress = true;
                e.Handled = true;
            }
            else
                base.OnKeyDown(e);
        }
    }
}

just override the textbox OnKeyDown
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

805 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