Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
 
System.ComponentModel.Container
System.Drawing.Size
System.Math
System.Windows.Forms.Form
System.Windows.Forms.FormStartPosition




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734