torsdag den 26. maj 2011

Visual Studio (2008) windows forms - c++ - tab order

So, since I've changed jobs I'm now stuck in VS2008.

And let me clarify something:
I HATE IT!

It is worlds from eclipse which I used before, and in most respects I mean this in a bad way.
The UI is littered with menu/options that don't work, in one view or another.
The dialog boxes (even though they are named the same) change function wether you're running an application or not, or if you've open a specific view/explorer.

To make matters worse, I'm tasked with maintaining an application written in C++ and winforms.
Don't get me wrong here; I like C++, and have worked with it for over 5 years, building linux apps and Qt GUI's.

Take the simple task of defining the tab order in a form; its a complete pain.
I googled the topic, because (as usual) I could not find a option for it in VS.
I found this on msdn: How to: Set the Tab Order on Windows Forms
But surprise, surprise, IT DOES NOT WORK!
I don't have the options/views; Absolutely nowhere can I find "Tab Order".
Designer view? Nope stuck in code view as well, but that's another story.

All hope is not lost though.
Open a file browser, navigate to the .rc file that contains your dialog, or other gui element, and open it using notepad++ or some other editor.

Here's the interresting piece of code from the file I'm working:

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_SIGNIN DIALOG  0, 0, 210, 122
STYLE DS_SETFONT | WS_POPUP | WS_BORDER | WS_SYSMENU
FONT 10, "Microsoft Sans Serif"
BEGIN
    LTEXT           "Indtast Medarbejdernummer",IDC_LBL_LOGINNUMBER,68,18,135,13
    EDITTEXT        IDC_EDB_LOGINNUMBER,68,35,113,12,ES_AUTOHSCROLL | ES_NUMBER
    LTEXT           "Indtast Loginkode",IDC_LBL_LOGINCODE,67,53,136,13
    EDITTEXT        IDC_EDB_LOGINCODE,67,70,113,12,ES_PASSWORD | ES_AUTOHSCROLL | ES_NUMBER
END

There are two Labels (LTEXT), and two Editable text input boxes (EDITTEXT).
Tab order is determined by the order they are listed, so if I wanted to change it, I would simply change the order in which they are listed.
Just note that elements that does not take focus will be skipped, so the two labels does not affect the tab order.
Default focus is the first element in the list that takes focus.

Now save the file, and you're done.

Oh, and watch what happens to VS when it gets focus again.
It says the file has changed, and if you wish to reload it.
If you press "yes" here VS will stop working and get restarted by windows.



How to: Set the Tab Order on Windows Forms