Solved

CTRL+A not working for textboxes

Posted on 2008-10-07
6
1,125 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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