CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Enter Key to Work as Tab key....

    Hello!
    I have a problem where i have a lots of textboxes to take input....so now whenever i enter a value in it and move on to another textbox I press 'Tab' key to shift between the texboxes so what I want to do is "Enter" key to do the same thing for me......ie Press Enter to shift to the Next Textbox......any one have idea on that please Help me.......

  2. #2
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Enter Key to Work as Tab key....

    by default there are keyboard driver codes to work according to there functionality , in u r case you may have to write extra to code to overcome those functionality.

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Enter Key to Work as Tab key....

    Rocky... why not just take the two keys off of your keyboard and swap them over???

    Because, when someone else uses your keyboard they will get confused.... Which is the whole point. Somebody who uses Windows exepcts the TAB to move the focus between controls on the screen. They expect ENTER to fire the default button.

    So, unless you have a really strong reason for doing this, I'd just swap the keys over on YOUR keyboard, that way it will still work as expected on other peoples.

    OK, A bit of humour, but with a serious message too.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  4. #4
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Enter Key to Work as Tab key....

    you could do something like this:

    Code:
    using System.Windows.Forms;
    
    namespace entertab
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == (char)Keys.Enter)
                    textBox2.Focus();
            }
    
            private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == (char)Keys.Enter)
                    textBox3.Focus();
            }
    
            private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == (char)Keys.Enter)
                    Submit();
            }
    
            private void Submit()
            {
                //do stuff.
            }
        }
    }
    but, as rliq said, this is probably not what your users will expect the application to do when they hit the Enter key...
    It's not a bug, it's a feature!

  5. #5
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Enter Key to Work as Tab key....

    I am doing this simple math game where young kids will feel easier to answer the next question after pressing enter isn't it??

  6. #6
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Enter Key to Work as Tab key....

    Maybe you could do it in a wizard-style with only one question per page..?
    It's not a bug, it's a feature!

  7. #7
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Enter Key to Work as Tab key....

    should i ask only x + y = ------- in a single page?? the whole page would be so much empty, plus I have 24 question and 24 text boxes area to take the answer....

  8. #8
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Enter Key to Work as Tab key....

    Well the page would be small then

    If I were to make an app like this, I would use a TabPage or similar Wizard layout and keep the questions/problems separate. Of course, it's up to you.
    It's not a bug, it's a feature!

  9. #9
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Enter Key to Work as Tab key....

    Why waste an entire form on this then ¿

    If you want the questions one by one, make use of an InputBox, and guess what, pressing Enter in an InputBox automatically dismisses it, storing your answer, and solving your Enter Key problem

  10. #10
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Enter Key to Work as Tab key....

    Quote Originally Posted by HanneSThEGreaT View Post
    Why waste an entire form on this then ¿

    If you want the questions one by one, make use of an InputBox, and guess what, pressing Enter in an InputBox automatically dismisses it, storing your answer, and solving your Enter Key problem
    I'll have to try that out never used that control before, but it sounds spot on
    It's not a bug, it's a feature!

  11. #11
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Enter Key to Work as Tab key....

    Which Visual Studio are you guys using?? because I cannot see Inputbox on my VS2008 using .net framework 2008?? please Help me out here....

  12. #12
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Enter Key to Work as Tab key....

    take a look at this
    It's not a bug, it's a feature!

  13. #13
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Enter Key to Work as Tab key....

    This could work for you...

    Code:
    // this would be a method that all textboxes would use.
    //  or you could be it into it's own method and call the method at the end of the
    //     individual event handlers of each textbox.
    private void AllTextBoxes_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            e.Handled = true;
            KeyEventArgs eInsertBack = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Tab);
            eInsertBack.RoutedEvent = UIElement.KeyDownEvent;
            InputManager.Current.ProcessInput(eInsertBack);
        }
    }
    Just make sure that your tab indexes are in the correct order.

    You probably should have stated that you were using WPF.
    ===============================
    My Blog

  14. #14
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Enter Key to Work as Tab key....

    I am extreamly sorry for that but AllTextBoxes_KeyDown is not working....it does not give any error either...when I put the names for each textboxes it works well but when I try to put AllTextBoxes it does not work with no errors either.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured