5

I Trying to switch Panel.TabStop property totrue but it does not affect anything.

How to enable TabStop in a Panel?

Timwi
  • 65,159
  • 33
  • 165
  • 230
DxCK
  • 4,402
  • 7
  • 50
  • 89
  • 2
    possible duplicate of [Panel not getting focus](http://stackoverflow.com/questions/3562235/panel-not-getting-focus) – Hans Passant Oct 01 '10 at 20:34
  • @Hans Passant: Thanks, I found the answer there, I just needed to add this line to my ctor: `this.SetStyle(ControlStyles.Selectable, true);` – DxCK Oct 01 '10 at 21:16
  • Well, don't cut it short. The user not being able to see the focus isn't great. – Hans Passant Oct 01 '10 at 21:20
  • I'll do the necessary things in `OnPaint`, this is not a problem for me. :) – DxCK Oct 01 '10 at 21:35

6 Answers6

1

A Panel does not accept keyboard focus because a Panel is not a control (per se), it's a container for other controls which probably accept keyboard focus.

If you're trying to create a custom control, derive from UserControl or Control.

Timwi
  • 65,159
  • 33
  • 165
  • 230
Tergiver
  • 14,171
  • 3
  • 41
  • 68
1

The TabStop property has no effect on the Panel control as it is a container object.

Checkout this MSDN Link for details.

Vinay B R
  • 8,089
  • 2
  • 30
  • 45
1

As the others have said, the panel control will not accept focus. However, if you set TabStop to true and set its TabOrder, then the next control in the TabOrder should receive focus.

Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
0

As I understand it, the TabStop property exists at the control level, but it really only affects what I would call interactive controls (there's probably an actual, correct term). Since panels can't directly receive the focus, they won't behave differently based on that flag.

Timwi
  • 65,159
  • 33
  • 165
  • 230
Steven
  • 1,260
  • 9
  • 22
0

You have to put something that can accept focus onto it, like editbox. There you go :)

Daniel Mošmondor
  • 19,718
  • 12
  • 58
  • 99
0

Try setting Focusable=true for the Panel you are using.

Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113