If application is activated, it is activated and got focus immediately, unless you screw up something, such are rendering of control. Question is not clearly formulating, because there three related aspects of showing application and focusing: 1) putting a form on top in Z-order, see
System.Windows.Forms.Form.BringToFront
; 2) activation, see
System.Windows.Forms.Form.Activate
; 3) getting keyboard focus; if the form has any controls (it should have, otherwise why would you need one :-)), focusing of the form makes no sense; one of the controls should be focused, see
System.Windows.Forms.Control.Focus
. If some control was focused before deactivation, it will be focused again on activation; you don't have to do it in code. Besides, you don't want loosing a change in focus the user have done before deactivation.
See:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[
^].
You can investigate why it goes so slowly; you can research order of operations and time them handling events
System.Windows.Forms.Form.Activated
and
System.Windows.Forms.Control
using
System.Diagnostics.Stopwatch
,
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx[
^]. It's hard to tell you more without looking at your code.
Why do you use
ShowInTaskbar = false
? Is does not make sense for main form of the application (but very useful for all other forms which should better be Owned). However, if this is a tray icon application, this is right thing to do.
—SA