Link to home
Start Free TrialLog in
Avatar of kranthi4uonly
kranthi4uonly

asked on

AUTO TABING PROPERTY IN WINDOWS FORM WITHOUT HITTING THE TAB KEY ANY ONE PLEASE HELP ME

i want to tab through all the controls in the windows form like for example if i say if the maximum sieze of a text box is reached it should go to next control and to next control like check box once it is checked next to drop down list next to other controls liek tht can any one please help me out
Avatar of anyoneis
anyoneis
Flag of United States of America image

I did this on a 1.1 Windows Forms app, and it got pretty complicated. I had to handle the controls individually.

For TextBoxes, I used KeyPress and Leave handlers. In Keypress, I do my special stuff, set e.Handled true,  then call SelectNextControl((Control)sender, true, true, true, true) to advance when desired. In Leave, I check a reentrancy flag (in<controlname>JointExit), and if it is clear I call <controlname>JointExit(object sender, EventArgs e, bool leaving),  with the leaving flag set true.

In <controlname>JointExit(), I set the reentrancy flag, do my stuff, and if I want to tab ahead and I am NOT leaving already, I call SelectNextControl((Control) sender, true, true, true,true). Finally, I clear the reentrancyflag.

I call the joint exit routine from other controls, and when I do, I set the leaving flag false, so that the autocomplete stuff happens.


I'm sure this was obtuse... For textboxes, I do a similar thing. Here is some example code where a checkbox interacts with a textbox:

[Code]
            private void countyMonthsCheckBox_Leave(object sender, System.EventArgs e)
            {
                  if (inCountyTimeJointExit == false)
                        countyTimeJointExit(sender, e, true);
            }
            private void countyMonthsCheckBox_CheckedChanged(object sender, System.EventArgs e)
            {
                  if (inCountyTimeJointExit == false)
                        countyTimeJointExit(sender, e, false);
            }

            private void countyTimeTextBox_Leave(object sender, System.EventArgs e)
            {
                  if (inCountyTimeJointExit == false)
                        countyTimeJointExit(sender, e, true);
            }
            
            bool inCountyTimeJointExit = false;
            private void countyTimeJointExit(object sender, System.EventArgs e, bool leaving)
            {
                  try
                  {
                        inCountyTimeJointExit = true;

                        <yada, yada>
                                    if (leaving && IDontWantToLeave )
                                          ((Control) sender).Focus();
                                    else
                                          SelectNextControl((Control) sender, true, true, true,true);
                                    if (!leaving && IDoWantToLeave)
                                          SelectNextControl((Control) sender, true, true, true,true);
                  }
                  finally
                  {
                        inCountyTimeJointExit = false;
                  }
            }
[/Code]

You get the idea.... Cover both "leave" events and the autocomplete event ("keyup" for textboxes, "selectedindexchanged" for comboboxes, "checkchanged" for checkboxes. Use a JointExit routine with a "leaving" flag. Protect that routine with a reentrancy flag. (This is needed since when the joint routine changes focus , you don't want it to be called again) Also, in that routine, select the next control if not leaving already. Or, select the current control if you are leaving and you don't want to.

This code worked great - the operators loved not having all of the extra tabbing and having autocomplete. It was developed for 1.1, and some things might be easier to do now in 2.0. However, this code still works.

David



Avatar of kranthi4uonly
kranthi4uonly

ASKER

like i cant see the  "IDontWantToLeave"  in the inteliisense in vs 2005 can u help me with this please
and also i cant see "IDOWANTTOLEAVE"
ASKER CERTIFIED SOLUTION
Avatar of anyoneis
anyoneis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi david thnaks for ur help but iam a fresher recently i started with .net can u please give the whole code please i had tried but this is not going to next control can uplease give me the code please