My blog has moved! Redirecting…

You should be automatically redirected. If not, visit http://www.digitalfugu.com/blog/ and update your bookmarks.

Friday, October 12, 2007

Update: Showing Form Without Stealing Focus

Remember I was using an API call to ShowWindow to show our custom window w/o stealing focus but had to set the visibility property programatically to get the form working properly? No? That was what we were doing but we've found something much cleaner.

More digging through MSDN showed that you can override a form's ShowWithoutActivation property to always return true to get the same effect. This allows you to use the normal Form.Show() method and all it's automatic goodness. However, this is only available in .Net Framework 2.0 or later. If you are in the 1.0 or 1.1 world, you'll need to do the P/Invoke to call the ShowWindow API.

The code looks like this:
protected override bool ShowWithoutActivation
{
get
{
return true;
}
}
It is like magic. I'm liking it a lot.

2 comments:

E. L. Pheterson said...

like magic

Motionless Mario said...

Indeed. I'm interested in finding out what type of application you are applying the magic to.