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?
--
wr

Re: MessageBox and Focus by Carlos

Carlos
Mon Jan 03 10:16:39 CST 2005

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


"WhiskyRomeo" <WhiskyRomeo@discussions.microsoft.com> escribió en el mensaje
news:EF3DEDBE-9CA5-45B2-B789-D5790AA33231@microsoft.com...
>
> 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?
> --
> wr



Re: MessageBox and Focus by Herfried

Herfried
Mon Jan 03 11:36:57 CST 2005

"WhiskyRomeo" <WhiskyRomeo@discussions.microsoft.com> schrieb:
> 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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



RE: MessageBox and Focus (Carlos, Herfried) by WhiskyRomeo

WhiskyRomeo
Tue Jan 04 17:39:09 CST 2005

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

Bill

"WhiskyRomeo" wrote:

>
> 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?
> --
> wr