Solved

bring a WinForm into focus

Posted on 2009-04-01
8
572 Views
Last Modified: 2013-12-17
How do you bring a WinForm into focus?

i.e. have multiple WinForms opened -- want to be able to instruct a WinForm to come forward (on top) so that WinForm's content can be viewed.
0
Comment
Question by:amillyard
8 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24038033
What kind of application do you have ?
A single or multiple document interface ?

Focus Form
http://www.java2s.com/Code/CSharp/GUI-Windows-Form/FocusForm.htm
0
 

Author Comment

by:amillyard
ID: 24038280
code snippet is how I create and initially show the window.

obviously, other windows can be opened at any time and/or the user minimise windows -- want to be able to programmically make a window the current window (just as if you have clicked it yourself manually)
public static FormABC formABC;
 
if ((formABC != null && !formABC.IsDisposed)) return;
 
formABC = new FormABC { Owner = this };
formABC.Show();

Open in new window

0
 
LVL 6

Expert Comment

by:HarryNS
ID: 24038975
All the forms should have been opened from one Parent form. You need to trigger an event or call a public member to make desired form to bring at the top level from Parent Form.

You can access the parent form by this.ParentForm...
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:amillyard
ID: 24040310
HarryNS: sorry...a little confused ...

I understand the concept of launching all WinForms from a main for etc.

but a bit lost with:  "You can access the parent form by this.ParentForm..."  

I know how to access the main WinForm -- just needed to know what triggers a window to become Top Level / active window
0
 
LVL 22

Accepted Solution

by:
Snarf0001 earned 500 total points
ID: 24040837
You still have a reference to formABC, right?
Easiest way is with

 formABC.Activate()
0
 

Author Comment

by:amillyard
ID: 24041325
Snarf0001:  I see.  Have applied suggestion -- I am getting the following compiling error as follows:

Cannot access non-static method 'Activate' in static context
0
 
LVL 22

Expert Comment

by:Snarf0001
ID: 24041404
Are you calling this from within a static function?
0
 

Author Comment

by:amillyard
ID: 24041639
Snarf0001:  You triggered a thought -- which resolved the issue -- I was not calling the WinForm from the right place -- i.e. from the source WinForm
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question