Control Tab Order in Visual Studio 2010

我与影子孤独终老i 提交于 2019-12-07 08:06:15

问题


Is there an easy way of changing the tab order of controls on a complicated form in the Visual Studio forms designer.

I know that I can select the Tab Order mode and it shows me all the controls with their tab index, but it is such a pain to add a new control in the middle of a complicated form and have to reselect EVERY control on the form again to set the new tab order. I often find that I have accidentally missed a control and so have to do it all over again.

I read on MSDN that it should at least be possible to Ctrl-Click on the control previous to where I want to start the new control reordering and then click on each contol after that to set the new the tab order, but I can't get that to work. Ctrl-Clicking the previous control just sets that one to Tab Index 0 and so that becames the new first control on the whole form.

I come from a delphi background and in delphi when editing the control tab order you get a dialog showing a list of all the controls on the form and you can select a control from the list and move it up or down the list. Much easier for a simple change like swapping tab order or adding a new control in to the middle of a form. Perhaps I am missing something, and it is possible to do this easily. If not available in Visual studio is there an add in that mimics the delphi functionality.

Regards Brian


回答1:


If you add a new control and give it a tab order value that is used, Visual Studio will automatically replace the rest. Both controls will have the same tab order, but it will work.




回答2:


The easiest way to change your tab order if you have too many control, simply open your PROJECT.RC file in text mode and locate where your dialog is configure.... for example:

IDD_MESSAGE_LIST DIALOG 0, 0, 197, 162
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Message List"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,85,140,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,140,140,50,14
    CONTROL         "List1",IDC_MESSAGE_LIST,"SysListView32",WS_BORDER | WS_GROUP,5,5,165,120
    CONTROL         "",IDC_LINE,"Static",SS_ETCHEDHORZ,5,130,190,1
    CONTROL         "",IDC_CHECK_ALL,"Static",SS_BLACKFRAME | NOT WS_VISIBLE,175,5,5,5
    CONTROL         "Tree1",IDC_MESSAGE_TREE,"SysTreeView32",TVS_HASBUTTONS | WS_BORDER 
END

Between BEGIN and END your controls are ORDERED by their TAB ORDER. Simply move the line corresponding to where you want your TAB ORDER. Simply SWAP the first two lines and it will be Cancel button as tab order 1.




回答3:


As you indicate that rearranging the forms is not an option you may consider using an old faithful from CodeProject: Automatic Runtime Tab Order Management for Windows Forms. It's a bit outdated (no strong typed generic collections for instance) but it works pretty well.

The TabOrderManager.cs from the project can be compiled on its own, you (I) don't need all the paraphernalia of the companion IExtenderProvider and the test project.

If a form needs change you could just add new controls and below InitializeComponent(); add a call like

new TabOrderManager(this).SetTabOrder(TabOrderManager.TabScheme.DownFirst);

Hope it suits you.



来源:https://stackoverflow.com/questions/7718463/control-tab-order-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!