Creating non full screen forms and custom MessageBoxes

A screenshot of a custom message box form which is not full screen.Every now and then someone asks how to create a .NET Compact Framework form which does not cover the fullscreen. Here is my solution to this problem.

This solution is built upon details discussed by other bloggers, including:

The trick is to set the form’s FormBorderStyle property to None. This disables the .NET Compact Framework’s built in functionality which forces a form to become fullscreen (on Windows Mobile devices), but also has the side effect of removing the border around the edge of the form. We can add the border (and a caption) back via the use of some PInvoke calls into the native operating system.

Points of interest

I decided to create my solution as two classes which are designed to be reusable within your own applications. One class enables the non full screen functionality, while the other provides an implementation for a common reason why non full screen forms are requested. These classes are as follows:

  1. NonFullScreenForm – a base class which you can use instead of Form. This base class allows you to have a form which does not cover the entire screen, and will optionally automatically center the form in the middle of the screen.
  2. MessageBoxForm – this is a subclass of NonFullScreenForm which provides a static method called Show. This method behaves in a similiar way to the standard MessageBox.Show API, with a few extensions such as the ability to use custom buttons.

Example Application

[Download nonfullscreendemo.ZIP 32Kb]

The example application available for download demonstrates the use of the NonFullScreenForm and MessageBoxForm classes via a series of buttons.

The first two buttons compare the behaviour of the standard MessageBox.Show API against our custom MessageBoxForm implementation for a number of message box styles. You will notice that the look and feel of our custom message boxes are similiar, but often have a slightly different layout.

The button labeled “Auto Centered Form” demonstrates the effect of setting NonFullScreenForm’s CenterFormOnScreen property to True. Whenever you tap the “Expand” or “Collapse” buttons the form changes size, and the NonFullScreenForm base class automatically changes the location of the form to ensure it is centered at all times. It will even re-center the form when the device switches between landscape and portrait modes.

How to use the NonFullScreenForm class

To use the NonFullScreenForm class within your own applications follow these steps:

  1. Add NonFullScreenForm.cs to your project.
  2. Set the FormBorderStyle property of your form to None.
  3. Set the Size and Location properties of your form to the desired size and position on the screen.
  4. View your form’s source code and change the form to derive from NonFullScreenForm instead of Form.
  5. If you want your form automatically centered on the screen set the CenterFormOnScreen property to true.
  6. If you don’t want an [OK] button in the caption, set the ControlBox property to false.

There are a number of areas where these custom controls could be improved. MessageBoxForm’s compatability could be improved. It does not support displaying an icon within the MessageBox at present for instance. There is also a slight flickering on the navbar (the bar at the top of the device which contains the start menu etc) when a non full screen dialog is created which would be nice to eventually remove. This is caused by the .NET Compact Framework dispaying the form before we have had a chance to change it’s window style to include a caption.

These controls were quickly put together to demonstrate what could be possible with a little bit of work. If anyone is interested in collaborating to improve these controls, I would be keen to hear from them.

23 Responses to “Creating non full screen forms and custom MessageBoxes”

  1. oldSAP says:

    Hi, i tried this using VB .NET on my smartphone but my form is still in Full Screen.
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    Me.ControlBox = False
    Me.MinimizeBox = False
    Dim hWnd As IntPtr = FindWindow(Nothing, “PopUp”)
    SetWindowPos(hWnd, IntPtr.Zero, _
    25, 25, 25, 225, SWP_SHOWWINDOW)

  2. SueS says:

    I was unable to open your demo project in my VS 2005. Can you help me?

  3. SueS says:

    Doyou have a version that will work on WM2003 SE + CF1.0 ?

  4. Hi,

    Recently I’ve had a number of requests/questions about the compatability of this code in various environments.

    Since it’s essentially trying to hack around undocumented/internal aspects of the .NET Compact Framework’s System.Windows.Forms implementation it was always going to be rather fragile with respect to various software/hardware configurations.

    As I said in the original article:

    These controls were quickly put together to demonstrate what could be possible with a little bit of work. If anyone is interested in collaborating to improve these controls, I would be keen to hear from them

    I’ll try to take a look at this code over the upcomming weekend, but no promises…

  5. zzy says:

    thank you ,it maybe helpful to me

  6. Santosh Ingawale says:

    Hi Christopher,
    I would like to thank you. that ur code helps me lot.
    and its works greatly in my application.
    but my requirement is something more..
    u kno when we connect PDA to USB thru active sync.
    that time one popup window appears on the screen of PDA
    Connecting… like and it disappers after few seconds,
    the say way i tried but . here probelm is ShowDialog returns DialogResult
    and definitely it requires button.
    if m here handling runtime click event for button on form still i dont kno how to assign return value to DialogResult…

    but i here dont want any button or Control box on the dialogform. only this dialog has to appear for few seconds and disappear automatically without clicking any button or control box.(i will dispose the form).

    So, do u have any idea how to do this.
    or is thr any special control for popup..(i guess not.)

    looking for some positive outcome from ur side……

  7. Udara says:

    thanks, Christopher!
    this was a really helpful to me..

  8. Echilon says:

    Cheers. Very useful class.

    To show a dialog with buttons of your choice, you can initialize the dictionary on instantiation – Eg:
    // Called from a System.Windows.Forms.Form
    “Looks like you need waffles, am I right?”,
    “Waffles needes”,
    new Dictionary() {
    { “Good observation”, DialogResult.Yes },
    { “We have no maple syrup”, DialogResult.No }
    { “I hate waffles”, DialogResult.Cancel }
    }) == DialogResult.Yes) {
    // etc

  9. Paul says:


    I’ve run into a big problem with your NonFullScreen class. If I have a form derived from that class, and I call ShowDialog() then it works great. But if I call Show() to have a non-modal dialog, then nothing displays.

    Please tell me there is a simple fix, to get this working.


  10. Paul says:

    I may have found it.
    If I call Refresh() after Show() then the form displays.

  11. Bax says:

    Thank you, your tip is very useful to me!

  12. Roy says:

    Hello. Ive seen a form that has remove the “start button/windows button” in its controlbox. Any idea on how to do this?

  13. morten says:

    Thank you for sharing this.

    It aided me to make the caption stick to the dialog form in .NET 2.0.

  14. hannes says:

    oh! great stuff! you saved my day! thanks!

  15. Peter says:

    Have someone figure out how to remove “windows start button” from the top of the screen?

    In my app all forms are maximized to hide this “start button” but I don’t know what to do with “non fullscreen forms”…

    please write me on “”

  16. Jacques says:


    How to open this project..?

    what are the things to be needed to open this project,

    thanks in advance,

  17. Stephan N says:

    Hi, I also use only maximized Forms in my solution and I would like to have that the Windows Startbar isn’t viewable when my non FullScreenForm is visible.

    Any suggestions?


  18. Rags says:

    When i use InputForm() in my baseForm as a showDialog it is not displaying my onescreen keyboard in WM 5 and in 6. But it is displaying in your demo code. Any idea? What are the possible way to get this fixed?

  19. dave says:

    This is terrific. Thanks so much!

  20. Laxmikant Mohanty says:

    Thank you for such a nice application ..

    It works fine ..

  21. Laxmikant Mohanty says:

    I have made one more enhancement which makes it auto close..

    we can set the time after which it automatically closes..

  22. Chris says:

    Thanks for providing this.

    I am a VB coder and I created a new C# SmartDevice application which was configured as a Class Library. I copied the code from NonFullScreenDemo.cs to the class code file and built a DLL which I can now reference in my projects. As you have mentioned, I change the Inherits statement at the top of the FormX.Designer.vb file to read:
    Inherits NonFullscreenDemo.NonFullscreenForm

  23. Maxim says:

    Works fine in VS2008 with win mobile sdk 6. Thank you very much, it helped us.

Leave a Reply