Forcing a window into the foreground

D

dhbayne

Hi All,

I am trying to write an application (an OOS exercise tool) that will
periodically display a form in the foreground, and move back to the
foreground every time it loses focus, or once every 1/10th of a second
by a timer.

The problem is that myForm.BringToFront() isn't working; the
application is highlighted in the taskbar, but the application window
itself stays behind any other windows (e.g. SharpDevelop) that're in
the foreground.

Is there any way of doing what I want? I've tried using DllImport to
invoke the SetForegroundWindow() function in user32.dll, but that has
exactly the same effect as the C# BringToFront() method.

TIA,
Duncan Bayne
 
G

Guest

I set the form's TopMost boolean property for this function. It works fine
in a VB application.
 
H

Herfried K. Wagner [MVP]

I am trying to write an application (an OOS exercise tool) that will
periodically display a form in the foreground, and move back to the
foreground every time it loses focus, or once every 1/10th of a second
by a timer.

You'll have to use p/invoke with 'AttachThreadInput' +
'SetForegroundWindow'.
 

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