bring screen to foreground

G

Guest

hi guys.

There are two screens and one thread on my project.

When App starts, first call screen1, screen1.showdialog();
When user select menuitem on screen1 to call scrren2, it will
show screen2.showDialog();

Issue: When screen2 is shown, and the background thread check some
information, and the result need to close screen2. but when thread invoke
the event
to close screen2, the whole app runing on background.

what I want to do is: when screen2 is closed, app automatically bring
screen1 to
foreground.
Can I directly call BringToFront or Active?


I have wroten some source code on BlackBerry:
when I call screen1.show(),screen2.show(),
if I close screen2.show(), the screen1 will automatically become current
screen if the this app is current application..

Thanks
 
H

houghtelling

I think you will have to do this through P/Invoke.

[DllImport("coredll.dll")]
public static extern bool SetForegroundWindow(IntPtr hwnd);

[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();

form1.Capture = true;
IntPtr hwnd = GetCapture();
form1.Capture = false;
SetForegroundWindow(hwnd);
 
N

Norman Rericha

I think you might want to rethink your design. When you say "screens"
I am going to assume that you mean Forms (mostly because ShowDialog).

It is a good idea to keep your application to 1 main form, with support
modal forms. If you are switching "screens" you can use panels instead.
By using panels you can use the main form to control when each are
being used.

Controlling the visibilty of forms can be a pain that you might want to
try and avoid.

I hope this helps,
 
G

Guest

What the other person said is correct for this WM "issue". But you didn't say
if you were using CF1.0 or CF2.0. If using CF2.0 then instead of using
GetCapture to get the hwnd of the form, you can use the Handle property of
the Form. Nice little feature of CF2.0 as P/Invokes are expensive, no need to
use them if you don't have to.

Simon.
 

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