How prevent the form hide after the dialog close (C# Windows Mobile)

856 views Asked by At

I'm doing a mobile application, all is almost as WindowsForms but when I close a MessageBox that provoque the multiple dialogs close with DialogResult in DialogResult.OK I find a problem, the main form it hides.

The structure is as follows:

enter image description here

program.cs

Application.Run(new From1());

Form1

Dialog1 frmDialog1 = new Dialog1());
frmDialog1.ShowDialog(this);

Dialog1(Windows Parent)

Dialog2 frmDialog2 = new Dialog2());
frmDialog2.ShowDialog(this);

if(frmDialog2.DialogResult == DialogResult.OK)
{
 this.DialogResult = DialogResult.OK;
 this.Close();
}

Dialog2(Windows Parent)

Dialog3 frmDialog3 = new Dialog3());
frmDialog3.ShowDialog(this);

if(frmDialog3.DialogResult == DialogResult.OK)
{
 this.DialogResult = DialogResult.OK;
 this.ParentForm.Hide();
 this.Close();
}

Dialog3(Windows Parent)

if (MessageBox.Show("Do you want to save?", "Save?", 
                MessageBoxButtons.YesNo, 
                MessageBoxIcon.Question, 
                MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
  this.DialogResult = DialogResult.OK;
  this.ParentForm.Hide();
  this.Close();
}

**Note: I'm using [DllImport("coredll.dll")] to show full screen

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

[Flags()]
public enum FullScreenFlags : int
{
    SwHide = 0,
    ShowTaskbar = 0x1,
    HideTaskbar = 0x2,
    ShowSipButton = 0x4,
    HideSipButton = 0x8,
    SwRestore = 9,
    ShowStartIcon = 0x10,
    HideStartIcon = 0x20

}
static class FullScreen
{

    #region Win32 API Calls

    /// <summary>
    /// The GetCapture function retrieves a handle to the window 
    /// </summary>
    /// <returns></returns>
    [DllImport("coredll.dll")]
    private static extern IntPtr GetCapture();

    /// <summary>
    /// The SetCapture function sets the mouse capture to
    /// the specified window belonging to the current thread
    /// </summary>
    /// <param name="hWnd"></param>
    /// <returns></returns>
    [DllImport("coredll.dll")]
    private static extern IntPtr SetCapture(IntPtr hWnd);

    /// <summary>
    /// This function can be used to take over certain areas of the screen
    ///  It is used to modify the taskbar, Input Panel button,
    /// or Start menu icon.
    /// </summary>
    /// <param name="hwnd"></param>
    /// <param name="state"></param>
    /// <returns></returns>
    [DllImport("aygshell.dll", SetLastError = true)]
    private static extern bool SHFullScreen(IntPtr hwnd, int state);

   /// <summary>
    /// The function retrieves the handle to the top-level 
    /// window whose class name and window name match 
    /// the specified strings. This function does not search child windows.
   /// </summary>
   /// <param name="lpClass"></param>
   /// <param name="lpWindow"></param>
   /// <returns></returns>
    [DllImport("coredll.dll", SetLastError = true)]
    private static extern IntPtr FindWindowW(string lpClass, string
    lpWindow);

    /// <summary>
    /// changes the position and dimensions of the specified window
    /// </summary>
    /// <param name="hwnd"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="w"></param>
    /// <param name="l"></param>
    /// <param name="repaint"></param>
    /// <returns></returns>
    [DllImport("coredll.dll", SetLastError = true)]
    private static extern IntPtr MoveWindow(IntPtr hwnd, int x, int y, int
    w, int l, int repaint);
    #endregion

    #region General Methods

    /// <summary>
    /// obtain the window handle of a .Net window or control
    /// </summary>
    /// <param name="c"></param>
    /// <returns></returns>
    public static IntPtr GetHWnd(Control c)
    {
        IntPtr hOldWnd = GetCapture();
        c.Capture = true;
        IntPtr hWnd = GetCapture();
        c.Capture = false;
        SetCapture(hOldWnd);
        return hWnd;
    }

    /// <summary>
    /// Set Full Screen Mode
    /// </summary>
    /// <param name="form"></param>
    public static void StartFullScreen(Form form)
    {
        //if not Pocket Pc platform
        if (!Platform.PlatformDetection.IsPocketPC()) 
        {
            //Set Full Screen For Windows CE Device

            //Normalize windows state
            form.WindowState = FormWindowState.Normal;

            IntPtr iptr = form.Handle;
            SHFullScreen(iptr, (int)FullScreenFlags.HideStartIcon);

            //detect taskbar height
            int taskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;

            // move the viewing window north taskbar height to get rid of the command 
            //bar 
            MoveWindow(iptr, 0, -taskbarHeight, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height + taskbarHeight, 1);


            // move the task bar south taskbar height so that its not visible anylonger 
            IntPtr iptrTB = FindWindowW("HHTaskBar", null);
            MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width, taskbarHeight, 1);
        }
        else //pocket pc platform
        {
            //Set Full Screen For Pocket Pc Device
            form.Menu = null;
            form.ControlBox = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.WindowState = FormWindowState.Maximized;
            form.Text = string.Empty;
        }
    }

    /// <summary>
    /// Stop Full Screen Mode
    /// </summary>
    /// <param name="form"></param>
    public static void StopFullScreen(Form form)
    {
        //if windows ce return window and taskbar to his original place
        if (!Platform.PlatformDetection.IsPocketPC())
        {
            IntPtr iptr = form.Handle;

            SHFullScreen(iptr, (int)FullScreenFlags.ShowStartIcon);

            //detect taskbar height
            int taskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;

            MoveWindow(iptr, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height - taskbarHeight, 1);

            IntPtr iptrTB = FindWindowW("HHTaskBar", null);
            MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height - taskbarHeight, Screen.PrimaryScreen.Bounds.Width, taskbarHeight, 1);

        }
    }

    #endregion
}

**Other comment:

I´m calling this.ParentFormHide(); because I desire that the parent it is hide before then close it. This for prevent then it show wrong, as like the follows:

This is shown when is closing multiple dialogs in cascade

This is shown when is closing multiple dialogs in cascade

If you know a way to prevent this animation on closing multiple dialogs, please share to me. At present to prevent this, I'm hiding the previous dialog before to close it.

Thanks in advance

0

There are 0 answers