You must Sign In to post a response.
  • Category: Windows

    How to textbox focus setting in c#

    Hi

    I have 4 textbox , 2 checkbox, 1 Dropdownlist and 1 multiple textbox in the windows application

    how to focus move cursor next control for ex: text1 when i press enter key i need move cursor textbox 2 then etc checkbox and dropdownlist and multipletextbox

    now i added every control put press entry move to next control so i need customized this code so

    i need single code for all control setfocus based on tabindex in windows application c#

    any one solve this
  • #761731
    Why can not u try to set TabIndex and TabStop?
    By Nathan
    Direction is important than speed

  • #761732
    Hi
    nathan

    I put tabindex order correctly but user press the enterkey how to focus next control one statment how will do this

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761733
    hi,
    there is key_down event for text box. in that, write code to for focusing
    private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    if (e.KeyCode==13)
    {
    textbox1.focus()=true;
    }
    }

    Do Good... Enjoy your life.....

  • #761734
    hello
    Arun

    Please understand my issue .

    I do not need every control i put this so i need global method for focusing control purpuse

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761736
    Hai JaiKumar,
    When pressing {Enter} key, you need to increase the TabIndex value so that the focus will automatically point to next control whose TabIndex is already set.
    By this way, when you press the {Enter} key, the focus will go to the next control whose TabIndex is 1 addition to the previous TabIndex value.

    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    if (e.KeyCode==13)
    {
    TabIndex +=1;
    }
    }

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #761753
    Please check out the below code. So when you press enter key the focus is on next control. Assuming that I have three textbox one after another then two checkbox and then one dropdown list.

    private void textBox1_KeyUp(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter)
    textBox2.Focus();
    }

    private void textBox2_KeyUp(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter)
    textBox3.Focus();
    }

    private void textBox3_KeyUp(object sender, KeyEventArgs e)
    {

    if (e.KeyCode == Keys.Enter)
    checkBox1.Focus();
    }

    private void checkBox1_KeyUp(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter)
    checkBox2.Focus();
    }

    private void checkBox2_KeyUp(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter)
    comboBox1.Focus();
    }

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #761756
    Hello
    Priya Jain


    I know this code for keypress every control suppose in my form 20 controls means i need to create 20 times this keypress?

    so i need one global method for this keypress next control focus thats my need



    I do not need every control keypress,every control keypress

    in my question i mention this

    i need single code for all control setfocus based on tabindex in windows application c#

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #763178
    hi,

    You can use key press of textboxs so that when user enter data in textbox 1 and hit enter key then cursor move to textbox2 like wise code for each textbox and you will get the answer.

    private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
    {
    if (e.KeyChar == 13)
    {textbox2.Focus();
    }


Sign In to post your comments