none
Textbox inside the user control focus problem. RRS feed

  • Question

  • Hi guys. I'm facing the textbox focus problem. I have a winform application which uses such as tab to change the user control. And the user control is singleton. I need to set the default focus in the user control's textbox. I tried to set using the focus method in Load method of the user control. It works when the user control is first created. In this case, as my user control is singleton. When I switch it back from the other user controls, it lose the textbox focus. I am switching the user control by clearing the parent control and add only the one which to show. Any idea?

    Monday, January 22, 2018 12:52 AM

All replies

  • Hello guys. Right now I am facing the textbox focus problem inside an user control which is a singleton.I am using the textbox.Focus() in the Onload method of the user control. It works the first time when the user control is created. But the problem is if I change the user control and call it back again. It will lost the focus. I am changing the user control by clearing the parent controls and only add the user control which to show. How can I get the default focus in the textbox again after the user control is created and call it back again. 
    • Edited by Alex Feng Li Sunday, January 21, 2018 11:16 PM
    • Merged by Fei Hu Monday, January 22, 2018 5:29 AM The same question
    Sunday, January 21, 2018 11:12 PM
  • I am facing the textbox focus problem inside an user control which is a singleton.

    I think a better forum for this would be:

    Windows Forms General
    https://social.msdn.microsoft.com/Forums/windows/en-US/home?forum=winforms

    or

    Windows Forms Designer
    https://social.msdn.microsoft.com/Forums/windows/en-US/home?forum=winformsdesigner

    - Wayne

    Monday, January 22, 2018 12:21 AM
  • Hello,

     You will get quicker and more accurate help if you provide the actual code you are

    using that has the issue of concern. Otherwise, you leave diagnostics up to how we

    implemented User Control focus issues.

     

      Please use the following guidelines;

     1. Write an accurate Title when posting. Use code blocks instead of insert standard text.

     2. Describe the issue in detail, including Debug messages from IDE if any.

     3. Provide your actual code, not just where the error appeared, for us to examine.

     3. If your issue is with a non-Microsoft product then visit the Devs website for support.

     4. When an issues has been solved then close posting and give credit to those who were helpful.

     5. Along with number 4, please Post new questions on new issues from same project.

     

     It's not that we do not want to help you finish a project. It's just a matter of time saving so

    this issue is solved vs time wasted on initial investigation questions.  Not to say there will not

    be follow up question when we respond.

     

     Thanks :)

    Monday, January 22, 2018 12:25 AM
  • Hello  Alex,

    I have noticed that you post the same thread in Windows General Forum, I will merge the two threads for suitable support.

    Thanks for your cooperation and understanding.

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 22, 2018 5:27 AM
  • I am surprised that configuring the TextBox with TabStop=True, TabIndex=0 isn't sufficient. 

    Setting focus in a Load() method doesn't really help because it's only invoked when the control is created, not as the user navigates around the Form. 

    Actually, I consider trying to "force" Focus at any time to be a Bad Idea because it never does quite what you think it should (at least that's what I've found over the years in numerous Microsoft tools).  


    Regards, Phill W.

    Monday, January 22, 2018 12:16 PM