Solved

CTRL+A not working for textboxes

Posted on 2008-10-07
6
1,132 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 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