|
| 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)
|
|
|
| |
|
| |
| |
| 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 } }
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|