   [.net] C# TextBox in TabPage loses focus
  Hey guys.  I have a TextBox in a TabPage in a TabControl in my Form.Sometimes when I type, my TextBox loses focus, and I need to click in it again to refocus it.  I've added a handler for the TextChanged event because I need to know when the contents of the TextBox change.  Even if I add a manual Focus() call inside the TextChanged event, the issue continues to exist.Interestingly enough, this guy has the exact same symptoms: http://www.databaseforum.info/2/649478.aspx.  However, no response in his thread, either.It seems to be related to the TextBox being in a TabPage - I don't remember this issue happening when it wasn't in a TabPage; the poster in the linked thread noticed the same issue.Visual aid:The visual aid demonstrates the issue when my TabControl was part of a SplitterPanel.  Now I've change it to inside a GridLayoutPanel, thinking that the SplitterPanel was the issue.  However, even with the GridLayoutPanel, the same issue occurs.  Any ideas?Edit: Now I've moved it out of the TabPage, and it STILL HAPPENS.  This is really, really irritating.  Anyone have ANY ideas?  [sad][Edited by - nullsquared on May 17, 2010 8:21:49 PM]
  What are you doing in the TextChanged event?Just spitting out the text to the console in the TextChanged event, I cannot recreate this problem. Is the project something you can post somewhere?   ;  Maybe some undesired effect with the control navigation by keyboard. One thing comes to mind: Have you set the SplitContainers TabStop to false ? Maybe that helps (though you did not mention the tab key).Other than that: Provide some code or even a completely stripped down project to reproduce the effect for us. Since this is Windows.Forms, code alone might not help if it has something to do with properties set "wrong".unbird   ;  In the TextChanged I'm simply setting a boolean flag (member, not property) to true in order to, essentially, signal that the text is 'dirty.'It's incredibly hard to reproduce, especially considering it hasn't happened in the past; it's one of those bugs that appears out of no where, even though you haven't touch that code in a *long* time.And no, it's not the SplitContainer.  I moved it into a GridLayoutPanel and the same thing happens, except this time something else randomly gains focus.I'll try to make a small sample to demonstrate the issue, but it's going to be hard...   ;  Aha!  I managed to find a case to reproduce it: it only happens when my changed text results in an update of the program's GUI (in terms of adding/removing controls).  It seems that the new controls gain focus when they're created, and I have to refocus my text box.  Simply refocusing my text box after everything is set up fixes the issue, as far as I can tell [smile]   ;Quote:Original post by nullsquaredIn the TextChanged I'm simply setting a boolean flag (member, not property) to true in order to, essentially, signal that the text is 'dirty.'Quote:Original post by nullsquaredAha! I managed to find a case to reproduce it: it only happens when my changed text results in an update of the program's GUI (in terms of adding/removing controls). It seems that the new controls gain focus when they're created, and I have to refocus my text box. Simply refocusing my text box after everything is set up fixes the issue, as far as I can tellJust saying; those two statements seem to be in complete contradiction with each other.  There's no way anyone could have solved that problem using the information originally given :-pGlad to hear you found the problem, however!   