views:

21

answers:

3

Using Visual Studio 2008 and VB.NET ...

I've created a form (OpaqueForm), which is an intermediary form between other forms which I will open with ShowDialog. The idea is that when I want to show a form using .ShowDialog, this OpaqueForm, with an opacity other than 100%, sits in between the main form and the dialog form, effectively "greying out" the underlying main form.

The OpaqueForm has the FormBorderStyle property set to None, and accepts in the constructor a Form object on which it invokes .ShowDialog. The effect works fine, but there is one caveat. The task bar is also covered by the OpaqueForm; I am assuming because it has a FormBorderStyle of None and a WindowState of Maximized.

I don't want the OpaqueForm to cover the Task Bar, because it would be impolite to have my modal form lock out a user from switching between tasks. How could I go about preventing OpaqueForm from covering the Task Bar, too, while still using a FormBorderStyle of None?

+1  A: 

Why not put an "opaque" panel over the top of the other form. It doesn't make sense to make the whole user window opaque. Because if the application isn't running maximized, they'll want to click to other applications.

McKay
+1 - You are right, only cover the application's form, not the whole user window.
HardCode
+1  A: 

Not sure I see how this could happen. Just make sure that the overlay is displayed with Show(owner) so that it is always on top and that it has the exact same Size and Location as the overlayed form.

You'll find sample code for such an overlay in my answer in this thread.

Hans Passant
.ShowDialog(owner) worked, after sizing the form to match the underlying form.
HardCode
A: 

Set the size of the form's size to the screen's working area.

Dim f as New Form()
f.FormBorderStyle = FormBorderStyle.None
f.Location = New Point(0, 0)
f.Size = My.Computer.Screen.WorkingArea.Size

this will do the trick.


Edit


If you need to place the Opaque Form on the Primary Screen, use the following code:

For Each scr In Screen.AllScreens
    If scr.Primary = True Then
        Dim f As New Form()
        f.FormBorderStyle = FormBorderStyle.None
        f.Location = New Point(0, 0)
        f.Size = scr.WorkingArea.Size
    End If
Next

If you want to place a form on every screen, just skip checking for the primary screen by removing the conditional.

Alex Essilfie
Is this multi-monitor compatible? I don't think so.
McKay
I edited the code so it supports multiple monitors.
Alex Essilfie