Solved

CTRL+A not working for textboxes

Posted on 2008-10-07
6
1,121 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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!
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now