Maximising a form with a menu.

  • Thread starter Thread starter Mark Bath
  • Start date Start date
M

Mark Bath

Programming in C# using Microsoft Visual Studio .NET 2003.

Application:
2 forms. Both are maximised with no minimise and no maximise buttons on
them.
The first form has no menu on it but the scond form does.

Problem:
The first form (the one without a menu on it) appears full screen. Great,
just what I want. However, this form then calls the second form on a button
press. This second form has a menu on it. What I get now is the the second
form appearing but I can still see the top portion of the first form behind
this second form.
The gap that is appearing appears to be roughly the same size as the space
filled by the menu bar at the bottom of the screen.
Both forms are the same size.

Does anyone know a way of getting rid of this gap that appears?
 
We're using an Intermec 700 device.
It's running Pocket PC 2003.

I'm using the code:
-------------
in Form1
-------------
private Form refForm2;

private void button1_click(object sender, System.EventArgs e)
{
this.refForm2 = new Form2.Manager();
this.refForm2.Show();
}
-------------
in Form2 (in initialize component)
-------------
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.MinimizeBox = false;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
-------------

I've also attempted to use:
this.refForm2.ShowDialogue();
in form1, but again the top part of the form is still missing (but at least
the user can't click on that portion of form1 that is still showing, and
hence go back to form1).
 
It seems that a main form captures a whole taskbar and other child forms
are placed below. Try code below to move the second form on top of
screen or use the SHFullScreen method (see my previous post):

protected override void OnActivated(EventArgs e)
{
base.OnActivated (e);

f.Capture = true;
IntPtr hWnd = GetCapture();
f.Capture = false;

if (hWnd != IntPtr.Zero)
{
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height, SWP_NOZORDER);
}
}

[DllImport("coredll")]
static public extern IntPtr GetCapture();

const int SWP_NOZORDER = 4;

[DllImport("coredll.dll", EntryPoint = "SetWindowPos", SetLastError = true)]
private static extern bool SetWindowPos(
IntPtr hwnd,
IntPtr hWndInsertAfter,
int x,
int y,
int cx,
int cy,
int uFlags);


Best regards,
Sergey Bogdanov
 
Back
Top