The code below will traverse controls, starting at the beginning (Form), and
assign a simple priority based on the actual tab order. These priorities are
stored in a hashtable using the control as the key.
private Hashtable priorities = new Hashtable();
/// <summary>
/// Get the controls on the form and assign a
/// priority based on the tab order.
/// </summary>
private void GetPriorities()
{
Control ctrl = this;
int priority = 0;
priorities.Clear();
while ((ctrl = this.GetNextControl(ctrl, true)) != null)
{
priority++;
this.priorities.Add(ctrl, priority);
}
}
Now if you wanted to get the priority for a given control...
object val = this.priorities[this.button1];
if (val is int)
{
// MessageBox.Show(val.ToString());
}
--
Tim Wilson
..Net Compact Framework MVP
"Markus Wildgruber" <ms********@syska.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi!
Is there a way to determine the (tab-)order of controls at runtime? My
goal is to get a unique number for each control on a form that could deal as a
priority value for that control.
The easiest approach is the TabIndex-property of all controls, but
unfortunately this does not work with several levels that exist when some
controls are placed on a panel.
I need a common approach to this problem because I don't know how the
forms will look like on whom that algorithm is run.
How can I get a real Z-order value that is unique for the whole form and
not just for the level?
TIA,
Markus