[MSH] Bringing form to front

11 views
Skip to first unread message

Grzegorz Niemirowski

unread,
Jan 26, 2006, 7:57:11 PM1/26/06
to
I have written very simple script for displaying images using Windows Forms.
It works well but there is one problem. Form is shown behind console window
so everytime a window with a picture is displayed I have to click it to
bring it to front. I have tried various methods of Form class but none of
them worked.

Here is the script:

param ( $file )
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form
$picturebox = New-Object System.Windows.Forms.PictureBox
$PictureBox.Image = [System.Drawing.Image]::FromFile($file)
$PictureBox.Width=$PictureBox.Image.Width
$PictureBox.Height=$PictureBox.Image.Height
$Form.Height=$PictureBox.Image.Height
$Form.Width=$PictureBox.Image.Width
$Form.Controls.Add($picturebox)
$Form.ShowDialog()

--
Grzegorz Niemirowski, Poland, Europe, www.grzegorz.net
OE PowerTool 3.1.5 - the best way to improve your OE
http://www.oept.it-faq.pl/
Uptime: 5 days, 6 hours, 11 minutes and 43 seconds

/\/\o\/\/ [MVP]

unread,
Jan 27, 2006, 2:47:35 AM1/27/06
to
you can use this :

$form.topmost = $true

but it keeps the form always topmost (like Taskmanager)

gr /\/\o\/\/

Grzegorz Niemirowski

unread,
Jan 27, 2006, 4:30:52 AM1/27/06
to
/\/\o\/\/ [MVP] <n...@Spam.mow> napisał(a):

> you can use this :
> $form.topmost = $true
> but it keeps the form always topmost (like Taskmanager)
> gr /\/\o\/\/

Does it work on your computer? It doesn't on mine.

--
Grzegorz Niemirowski, Poland, Europe, www.grzegorz.net
OE PowerTool 3.1.5 - the best way to improve your OE
http://www.oept.it-faq.pl/

Uptime: 5 days, 14 hours, 51 minutes and 30 seconds

Grzegorz Niemirowski

unread,
Jan 27, 2006, 4:50:47 AM1/27/06
to
Grzegorz Niemirowski <gnthe...@poczta.onet.pl> napisał(a):

> Does it work on your computer? It doesn't on mine.

OK, it works. I forgot that $form.topmost = $true must be placed before
$Form.ShowDialog()
I have also fixed the problem with topmost by disabling it just after the
form is shown. So now the end of script looks like this:

$form.topmost = $true
$Form.Add_Shown({$form.topmost = $false})
$Form.ShowDialog()
$form.topmost = $false

--
Grzegorz Niemirowski, Poland, Europe, www.grzegorz.net
OE PowerTool 3.1.5 - the best way to improve your OE
http://www.oept.it-faq.pl/

Uptime: 5 days, 15 hours, 10 minutes and 7 seconds

Reply all
Reply to author
Forward
0 new messages