Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to disable tab control in window form

How to disable tab control in window form

Scheduled Pinned Locked Moved C#
questiondatabasehelptutorial
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Duong Tien Nam
    wrote on last edited by
    #1

    I have a custom control in a form and I want it to catch the key I press, so I implement the "KeyDown" event, its ok but the event does not fire when I press TAB, Up, Down... (the keys that is used internal to change the tab index of control inside the form). How can I disable it and handle those special keys? Thank you for your help!

    M S L 3 Replies Last reply
    0
    • D Duong Tien Nam

      I have a custom control in a form and I want it to catch the key I press, so I implement the "KeyDown" event, its ok but the event does not fire when I press TAB, Up, Down... (the keys that is used internal to change the tab index of control inside the form). How can I disable it and handle those special keys? Thank you for your help!

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, When you use te KeyDown event the member 'KeyData' is what you are looking for.

      if(e.KeyData == Keys.Tab)
      {
      e.Handled = true; //prevents that Tab is pressed
      }

      All the best, Martin

      D 1 Reply Last reply
      0
      • M Martin 0

        Hello, When you use te KeyDown event the member 'KeyData' is what you are looking for.

        if(e.KeyData == Keys.Tab)
        {
        e.Handled = true; //prevents that Tab is pressed
        }

        All the best, Martin

        D Offline
        D Offline
        Duong Tien Nam
        wrote on last edited by
        #3

        But it is not go to the KeyDown method at all when you press Tab, we can not check it.

        1 Reply Last reply
        0
        • D Duong Tien Nam

          I have a custom control in a form and I want it to catch the key I press, so I implement the "KeyDown" event, its ok but the event does not fire when I press TAB, Up, Down... (the keys that is used internal to change the tab index of control inside the form). How can I disable it and handle those special keys? Thank you for your help!

          S Offline
          S Offline
          sam
          wrote on last edited by
          #4

          Hi, It may sound weird but if you want to trap the TAB key for a control then you should check it in the KeyUp event of the next control(Next Control : control is getting focuse On pressing Tab)

          1 Reply Last reply
          0
          • D Duong Tien Nam

            I have a custom control in a form and I want it to catch the key I press, so I implement the "KeyDown" event, its ok but the event does not fire when I press TAB, Up, Down... (the keys that is used internal to change the tab index of control inside the form). How can I disable it and handle those special keys? Thank you for your help!

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, AFAIK you should override IsInputKey(). :)

            Luc Pattyn [My Articles]

            M 1 Reply Last reply
            0
            • L Luc Pattyn

              Hi, AFAIK you should override IsInputKey(). :)

              Luc Pattyn [My Articles]

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Hello Luc, I also tried it, because I'm currious, but sadly it doesn't jump in the overriden method. Tried it in the MainForm and in an UserControl.

              	protected override bool IsInputKey(Keys keyData)
              	{
              		return base.IsInputKey (keyData); //Set my brakepoint here
              	}
              

              I read the msdn infos and know how it should work, but now I'm confused? Any hints? All the best and mercy, Marin -- modified at 11:45 Wednesday 28th February, 2007 Ok, just found out how to use it in an inherit TextBox for example:

              	protected override bool IsInputKey( System.Windows.Forms.Keys keyData ) 
              	{
              		switch ( keyData)
              		{
              			case Keys.Tab: 
              				return true;
              			default:
              				return base.IsInputKey(keyData);
              		}
              	}
              

              But it's not working on an UserControl or Form. All the best, Martin

              L 1 Reply Last reply
              0
              • M Martin 0

                Hello Luc, I also tried it, because I'm currious, but sadly it doesn't jump in the overriden method. Tried it in the MainForm and in an UserControl.

                	protected override bool IsInputKey(Keys keyData)
                	{
                		return base.IsInputKey (keyData); //Set my brakepoint here
                	}
                

                I read the msdn infos and know how it should work, but now I'm confused? Any hints? All the best and mercy, Marin -- modified at 11:45 Wednesday 28th February, 2007 Ok, just found out how to use it in an inherit TextBox for example:

                	protected override bool IsInputKey( System.Windows.Forms.Keys keyData ) 
                	{
                		switch ( keyData)
                		{
                			case Keys.Tab: 
                				return true;
                			default:
                				return base.IsInputKey(keyData);
                		}
                	}
                

                But it's not working on an UserControl or Form. All the best, Martin

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Hi Martin,

                Martin# wrote:

                But it's not working on an UserControl or Form.

                What do you mean by this ? Is your IsInputKey() not called at all ? (for regular chars, for TAB, arrows...) ? or is its return value simply ignored ? And for which .NET version is this observation ? I am using IsInputKey() on Panels only (both 1.1 and 2.0), no problem there. :)

                Luc Pattyn [My Articles]

                M 1 Reply Last reply
                0
                • L Luc Pattyn

                  Hi Martin,

                  Martin# wrote:

                  But it's not working on an UserControl or Form.

                  What do you mean by this ? Is your IsInputKey() not called at all ? (for regular chars, for TAB, arrows...) ? or is its return value simply ignored ? And for which .NET version is this observation ? I am using IsInputKey() on Panels only (both 1.1 and 2.0), no problem there. :)

                  Luc Pattyn [My Articles]

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #8

                  Luc Pattyn wrote:

                  s your IsInputKey() not called at all ? (for regular chars, for TAB, arrows...) ?

                  Yes, in all points! -- modified at 14:12 Wednesday February, 2007 I'm just rereading what I was answering before. I think it was not clear. What I meant, was that it is never called! -- modified at 5:09 Thursday 1st March, 2007 I'm only using 1.1

                  D 1 Reply Last reply
                  0
                  • M Martin 0

                    Luc Pattyn wrote:

                    s your IsInputKey() not called at all ? (for regular chars, for TAB, arrows...) ?

                    Yes, in all points! -- modified at 14:12 Wednesday February, 2007 I'm just rereading what I was answering before. I think it was not clear. What I meant, was that it is never called! -- modified at 5:09 Thursday 1st March, 2007 I'm only using 1.1

                    D Offline
                    D Offline
                    Duong Tien Nam
                    wrote on last edited by
                    #9

                    I tried it too, I override the IsInputKey method for the FORM, and the method was not called. According to MSDN, it should be called.....

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups