Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi How can I set focus to a textbox after messagebox on chrome browser?
I used some ways but without success
C#
if (MessageBox.Show("are you sure to delete?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
          {
              Textbox.Focus();
              System.Windows.Browser.HtmlPage.Plugin.Focus();
              this.Focus();

              Dispatcher.BeginInvoke((ThreadStart)delegate
              {
                  Textbox.Focus();
              });
              return;

              Textbox.Focus();
              this.Focus();

          }
Posted
Comments
Sergey Alexandrovich Kryukov 6-Oct-14 10:45am    
Return statement will give you compilation warning.
ThreadStart formally and accidentally match, but this is not a purpose of this delegate type. Use, say
BegingInvoke(new System.Action({} => { TextBox.Focus(); }));
(It won't solve the problem but would look more adequate; the signature of the delegated method could be anything.)

If you want to focus on Textbox, at least don't focus anything else. Also, you can set logical focus before calling MessageBox; the focus will return to logical focus, because the message window will disappear.

—SA
Angela 10293848 8-Oct-14 5:07am    
Hi Sergey
How can I set logical focus on textbox?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900