Multimobile Development: Building Applications for any Smartphone
CenterParent on MDI Child not working?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.


Bob Baldwin
Hi all you .Net gurus,

I am trying to use the CenterParent enumeration for the Form.StartPosition
property on an MDI child form and it is ignoring it. Any ideas?

I tried setting the property at design time and run time with no effect on
the starting position of the child form (starts in upper left of MDI
parent).

Here is some sample code:
Dim frm As New frmProducts()

frm.MdiParent = Me

frm.StartPosition = FormStartPosition.CenterParent

frm.Show()

Thanks in advance...Bob Baldwin (Versent)

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Nathan Alden
There are some aspects of forms that are ignored when a form becomes an MDI
parent. One of the biggest examples is how MDI children don't obey the
MinimumSize and MaximumSize properties. What I did to counteract these
strange things is write my own class. Through platform invoke, it will use
the MinimumSize and MaximumSize properties to determine if a WM_SIZING
message should be processed or killed. I'm sure you could add your own
functionality to it.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace NALibrary
{
/// <summary>
/// Provides an MDI child form that allows sizing restrictions.
/// </summary>
public class MdiChildForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;

/// <summary>
/// Initializes a new instance of the MdiChildForm class.
/// </summary>
public MdiChildForm()
{
InitializeComponent();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

/// <summary>
/// This member overrides Form.WndProc.
/// </summary>
/// <param name="m"></param>
protected unsafe override void WndProc(ref Message m)
{
if (m.Msg == (int) WindowsMessages.WM_SIZING)
{
WindowsRectangle * windowsRectangle = (WindowsRectangle *)
m.LParam.ToPointer();

if (MinimumSize != new Size(0, 0))
{
windowsRectangle->Width = Math.Max(MinimumSize.Width,
windowsRectangle->Width);
windowsRectangle->Height = Math.Max(MinimumSize.Height,
windowsRectangle->Height);
}
if (MaximumSize != new Size(0, 0))
{
windowsRectangle->Width = Math.Min(MaximumSize.Width,
windowsRectangle->Width);
windowsRectangle->Height = Math.Min(MaximumSize.Height,
windowsRectangle->Height);
}
}

base.WndProc(ref m);
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// MdiChildForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "MdiChildForm";

}
#endregion
}
}

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
 
System.ComponentModel.Container
System.Drawing.Size
System.Math
System.Windows.Forms.Form
System.Windows.Forms.FormStartPosition




Multimobile Development: Building Applications for any Smartphone
Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734