I have a Class(ChorNumbers) and in this class i have a Function that test textbox1…17 is a Character or a Number.
I create a WindowsForm that have 9 textboxs. And if i enter 1 in the textbox1 that must jump to next textbox2 (that do this) If i enter A in the textbox2 that must jump to textbo3, but they does not jump. Where is the Problem why it doesnt not Jump??
And i want a use one textbox1_TextChanged Function.
private void textbox1_TextChanged(object sender, EventArgs e)
{
TextBox myText = (TextBox)sender;
ChorNumbers myNR = new ChorNumbers();
bool _focused = false;
if (myNR.CheckTextbox(myText.Name, myText.Text) == false)
foreach (Control ctrtb in base.Controls)
if (ctrtb is TextBox && _focused == false)
{
_focused = ctrtb.Focused;
}
else if (ctrtb is TextBox && _focused == true)
ctrtb.Focus();
}
I have solution that i dont wanna use that. I want only one textbox1 function for the other textboxs
private void textbox3_TextChanged(object sender, EventArgs e)
{
TextBox myText1 = (TextBox)sender;
ChorNumbers myNR1 = new ChorNumbers();
if (myNR1.CheckTextbox(myText1.Name, myText1.Text) == false)
{
textbox4.Focus();
}
}
By
Do you mean that you only want a single call back function to be called by each textbox that then (if populated correctly) passes along to the next? If so, then that part is easy, just point each event handler to the same method (it may get complex though, unless the validation is exactly the same for each – therefore, it may be better to have one per textbox).
I think your problem is going to be a standard one – you are trying to change focus during an event called by that control before that control is finished processing. That is, textbox1, on being populated, fires the event which you catch – in your catchment (callback) method you change the focus – now processing returns to textbox1 (on return/end of you callback method) and focus is switched bach as a by-product (because the carat is being placed ready for next update by textbox1).
One solution is call a timed event for a few milliseconds later, then after processing returns to the textbox and it goes back into waiting for a message state, the timed event kicks off a focus (jump).
You could also try setting enabled to force and seeing if that forces the current control to pass anyway (will need to have sorted tab stops though)