[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

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
0
kranthi4uonly
Asked:
kranthi4uonly
  • 3
  • 2
1 Solution
 
anyoneisCommented:
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



0
 
kranthi4uonlyAuthor Commented:
like i cant see the  "IDontWantToLeave"  in the inteliisense in vs 2005 can u help me with this please
0
 
kranthi4uonlyAuthor Commented:
and also i cant see "IDOWANTTOLEAVE"
0
 
anyoneisCommented:
Haha! Those are just standins for conditional logic. For instance, if they are leaving the field and I'm not "happy" with what's there, I keep focus on the field. If they aren't leaving the field (ie we are not processing a leave event), and I have determined that I should auto complete, then I want to force focus to the next control. Note, that this does cause the leave event to fire, but it just returns because it detects the reentrancy flag is set.

Is that any better?

David
0
 
kranthi4uonlyAuthor Commented:
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
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now