Modal "pop-up" forms

E

Elisa

Hi,

If have an application where all of my main forms are fullscreen (e.g.
without any close buttons, titles, etc.). From these screens, I'd like
at times to pop-up a smaller non-fullscreen form (sort of like a message
box form, but with completely different content).

I tried creating a small form in the designer, and then calling
ShowDialog, but the Compact Framework automatically makes that form
fullscreen as well. Setting the FormBorderStyle to None seems a step in
the right direction, it allows for non-fullscreen forms, but as the
setting suggests, it indeed doesn't have a border (ugly), and more
importantly, if I show this form using ShowDialog, I can still click on
buttons on the underlying (calling) form, so it the ShowDialog method
doesn't seem to make my form act as a modal form!?

Two questions:

1. How do I get the border back (and preferably a title)?
2. Why doesn't ShowDialog make this form act as a modal form?

I know it must be possible somehow, because the File Explorer show a
similar form when you try to overwrite an existing file...


Regards,

Elisa
 
C

chris-s

Hi Elisa,

To 'get the border back', you could create a panel and drop your controls
onto that, tho' you'll have to create a custom panel to enable the border to
be displayed. As for the enabled controls, I found that the underlying
controls were unresponsive although you could click on the underlying form
which would change the focus without hiding the upper modal form, not sure
what to do to get around that.

Alternatively, you could either add a separate panel to the form to act as
the modal dialog box and hide it/show it as required, tho you would have to
disable the underlying controls which is easiest done by placing them on
there own panel and disabling the panel itself. If you need to show the same
dialog box from more that one form, then you could try creating a class that
itself represents the entire dialog box as a panel and instantiate it as
required.

Chris
 
C

Chris Tacke, eMVP

Actually the CF isn't making the Forms full-screen, the Pocket PC is. I
believe that the PPC design guidelines call for full-screen forms only, and
the platform enforces it. You can confirm this by running a vanilla CE app
and creating as many Forms that aren't full screen as you'd like.

The workaround that I've seen for those who still want a popup is to use a
borderless Form (which can be non-fullscreen) and then manually paint in the
title bar.

-Chris
 
E

Elisa

The workaround that I've seen for those who still want a popup is to use a
borderless Form (which can be non-fullscreen) and then manually paint in the
title bar.

I've know come up with this work-around:

1. Create a new Form.

2. Override the OnPaint and OnPaintBackground methods with empty
methods, this should make the form "transparent", but still prevents
access to the underlying form's controls:

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
' Do nothing
End Sub

Protected Overrides Sub OnPaintBackground(ByVal e As
System.Windows.Forms.PaintEventArgs)
' Do nothing
End Sub

3. Override the OnLoad method and make this Form full-screen:

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Me.WindowState = FormWindowState.Maximized
End Sub

4. Add a panel to this Form. Preferably, you'd create a custom-draw
panel with a border and a titlebar.

5. Call this Form from another form, et voila, it looks and feels like a
modal dialog box (ok, you can't move it, but not too many people will be
bothered about that).

Dim f As New MyFakeModalForm
f.ShowDialog()
f.Dispose()

Sounds good, or am I shooting myself in the foot by being to clever?


Regards,

Elisa
 
E

Elisa

Just a quick note:

It looks like non-fullscreen modal dialogs work fine if you install SP2...


Regards,

Elisa
 
C

Chris Tacke, eMVP

You mean just as is, or with some "added" code? I wasn't using any SP when
I ran my tests.

-Chris
 
E

Elisa

Hi Chris,

If you create a non-fullscreen form (e.g. set borderstyle to none,
specify width and height, ...), then call ShowDialog() on this form, it
will actually behave to way it should, without any additional code.
Before SP2, it was actual not behaving like a modal form at all, because
you could click on controls on the calling form.


Regards,

Elisa

----
 
C

Chris Tacke, eMVP

Gotcha -but you still have no title-bar. That's what I was trying to work
around, but I'm glad it's working for you now.
 
E

Elisa

Hi Chris,

Nope, title bar, border, the ability to move the form around, etc. are
all things we need to add ourselves...


Regards,

Elisa
 

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