MessageBox and Focus

G

Guest

I have a message box that pops up when there is a problem after a user
clicks on a button.

After the user clicks OK on the message box, I need the focus to return to a
different control (a textbox). Intuitively, you would think the line
MyTextbox.Focus after the MessageBox.Show line would do the the trick.
Howerver, focus always returns to the control that initiated the show method.
Any focus method after that is ignored.

Can anyone tell me how to overide this behaviour?
 
C

Carlos J. Quintero [.NET MVP]

I am unable to reproduce it. Try this using C# 2003: a form with a treeview
and a button, and this code:

private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Hi");
treeView1.Focus();
}

It works as expected, the focus goes to the treeview.

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
H

Herfried K. Wagner [MVP]

WhiskyRomeo said:
I have a message box that pops up when there is a problem after a user
clicks on a button.

After the user clicks OK on the message box, I need the focus to return to
a
different control (a textbox). Intuitively, you would think the line
MyTextbox.Focus after the MessageBox.Show line would do the the trick.
Howerver, focus always returns to the control that initiated the show
method.
Any focus method after that is ignored.

I am not able to repro that in VB.NET 2002 using 'MsgBox' or
'MessageBox.Show'.
 
G

Guest

Thanks for the replies. At least this allows me to look elsewhere for the
problem.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top