Pergunta

I have inherited a frankenstein VB6 "Converted" to VB.NET winform application. This application has a metric ton of fields in it, the users rightfully complained that the tab order is off (after a certain point it starts jumping all over the form).

Figuring something in tab order was off, I went in and turned on View > Tab Order and it looked good.

To be sure I went through the form again fresh and when I'm in tab order view all is well, but when the app runs it still starts jumping around the same area as before?! Has anyone else encountered this and how did you resolve if you did?

[Edit]: These input forms are all on separate tabs within a tab control, which probably muddies the situation even more.

Foi útil?

Solução

Are there any strange Focus calls in the code that are overriding the tab order and setting the focus of the application manually?

I've had problems in the past with tab ordering getting itself all confused and I've usually just resorted to going through the application from scratch and setting the order myself manually. I realise that this may well not be what you are looking for but I don't know of anything else

Outras dicas

If you have many controls on a form chances are that they are organized with containers such as panels and group boxes. When setting the tab order you have to consider the order of the containers as well. An inconsistency between tab orders on in the containers could explain the weird jumping. This can happen especially if two or more controls/containers have the same tab order value which makes the tabbing process arbitrary.

Solution Idea: Of course updating and correcting the tab order is slow, error-prone work. It may behoove you to write a routine that iterates through the form's containers and controls recursively and assigning tab order values properly. You would set the tab order by comparing the Location point of each control of the container where top and left most point is the "lower" rank and the bottom, right-most component is the "highest". This would of course need a custom sorting alg. And if you look around, something like this may already be out there.

Solution Idea 2: Refactor! Divide and conquer. It will take some time but if you move the UI components into separate, logically-organized user controls you'll get tighter of the codebase. You'll also uncover a lot of bugs!

Chances are, some of your controls are embedded in container controls, and the tab order of your container controls is causing the focus to appear as if it is jumping around randomly. Make sure that when you're in the tab order view, you pay careful attention to the tab order of your container controls: Make sure that none of them have the same tab order, and that they're ordered logically with the tab order of your individual controls.

Otherwise, you need to check your UI code for some calls to Control.Focus that could be interfering with the default tab order at run-time. Some validation code may be changing the focus to the "next" control after it completes successfully (or "back" to a previous control if validation failed).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top