theKindOfMe

November 8, 2008

Some notes about setting the tab order of controls in netcf

Filed under: Uncategorized — Tags: , , — yasi8h @ 3:55 pm

setting the tab order in visual studio is no thing. basically you can set the tab index property using the property grid or you can use the designer to set the tab order. how ever when you have panels in your form(i am talking about a winforms application). setting the tab order becomes a little bit more complicated. for example if we have a form and inside the form we have two text boxes and a panel. and inside this panel we are having another two text boxes. in this case if we want to set the tab order for these controls we have to do it like this. we have to set the tab order for the two text boxes on the form and also for the panel. and then, we have to set the tab order for the two text boxes inside the panel. basically all the controls inside the panel(or any other container control… i guess) have there tab order set separately from the any other controls in any other container. you can see what i mean if you look at the following screen shot. note that this is a .net full framework winfroms application.

image 1

But things are a bit different when it comes to the compact framework. in the netcf if you start a new project and put a form. and basically add all the same controls that we added to the previous project. now when we are going to set the tab index for these controls. you should notice something different. here the panel does not have tab index and tab stop properties(well at least they are not displayed in the designer). so as a result you cannot set the tab order for the panel. this mean you loose the ability to choose the tab order with the same level of flexibility that you had in the full framework.

image 2

but if you look in the panel control. it does have a inherited tab stop property as well as a tab index property. these properties although not displayed in the property grid or though the intellisense inside the visual studio. is still there. and they are been used by the tab order mechanism just as they are used in a full framework application. so basically what this means is you can have the same functionality that you had in full framework winforms app’s tab indexing in netcf apps. but how are you supposed to set the tab index of netcf winfomr’s controls as they are not displaying the properties? well you can set them in your code at the run time.

there might  be several ways to do this. one way would be to create your own panel. and add a custom property to it. for example. we can inherit from Panel and create something like MyPanel. in the which we can create two custom properties called MyTabIndex and MyTabStop.


using System.Windows.Forms;

namespace Winforms.CF.TabIndex.Test
{
public class MyPanel : Panel
{
public bool MyTabStop
{
get { return base.TabStop; }
set { base.TabStop = value; }
}

public int MyTabIndex
{
get { return base.TabIndex; }
set { base.TabIndex = value; }
}
}
}

note that when you type in base.TabStop and base.TabIndex the intelisense will not show you these properties. they are ‘hidden’ by default.

now that you have your custom control you can use that instead of the Panel control. this would let you set the tab index(and the tab stop property). which will enable you to set the tab index in all the controls just as you do in any full framework application. i don’t know the reasons for Panel control having these two properties hidden by default in netcf. there might be some reason(s) for this. or else it might be a bug even, who knows 🙂

btw if you try to put ‘new’ properties with the same name as TabIndex and TabStop in your custom control, they will not be visible in the property grid and will not get serialized by the designer. even if you apply some custom attributes like DesignerSerializationVisibility, Broswesable…. it will still not be visible.


using System.Windows.Forms;

namespace Winforms.CF.TabIndex.Test
{
public class MyPanel : Panel
{
public new bool TabStop
{
get { return base.TabStop; }
set { base.TabStop = value; }
}

public new int TabIndex
{
get { return base.TabIndex; }
set { base.TabIndex = value; }
}
}
}

this will not get serialized by the designer nor will it be visible through the property grid.

Advertisements

Create a free website or blog at WordPress.com.