views:

615

answers:

2

When I run my VB.NET Winforms app I do not want it to steal the focus from the other open apps. FYI, my app is started from the command line but that shouldn't make a difference. I've seen question 577076 but that doesn't seem to work.

What is the best way to do this?

A: 

In the example you linked, some constants are declared outside the scope of the method. Here is another version that should work for you:

protected CreateParams CreateParams {
  get {
    CreateParams baseParams = base.CreateParams;
    const int WS_EX_NOACTIVATE = 0x08000000;   
    const int WS_EX_TOOLWINDOW = 0x00000080;    
    baseParams.ExStyle |= (int) (WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW); 
    return baseParams;
  }
}
...

You're gonna have to translate it to VB.Net though...

Julien Poulin
Thanks Julien, you did answer my original question but that still didn't work to prevent form from stealing focus. I edited my question to make it clearer.
JapNolt
+2  A: 

Here is what I did to get this working:

I added the following code to my Form1.vb file:

Protected Overloads Overrides ReadOnly Property ShowWithoutActivation() As Boolean  
    Get  
        Return True  
    End Get  
End Property

But still no success.

Then I unchecked the Enable Application Framework checkbox on the Application tab of the project properties.

Success!!!

JapNolt
Here is an article on ShowWithoutActivation()http://msdn.microsoft.com/en-us/library/system.windows.forms.form.showwithoutactivation.aspx
Achilles