Winforms control layout bug
"Simon Guindon" <[email protected]>
| Newsgroups | gmane.comp.gnu.dotgnu.developer |
|---|---|
| Message-ID | <000d01c4c212$4e19cc90$6400000a@amdxp> |
Hey guys, this email is in response to my last one. I spent another 4 or so hours trying to track down this layout bug, and I assembled a simple to try test case. I'm looking for some feedback or insight on perhaps a solution. I've tried to figure it out but a little lost. The anchoring/sizing isn't happening properly. The control is a UserControl, not derived directly from Control. The Control is docked top, left and right. This is an app from VS.NET. PNET: http://home.sse.net/layoutbug1.jpg .NET: http://home.sse.net/layoutbug2.jpg The UserControl is anchoring properly, but child controls inside it, are not. VS.NET designer is setting the form to suspend layout, then calling ResumeLayout(false) after the controls are added to the form. But that means the controls are never getting PerformLayout() being called. I'm not sure if this is the issue or not. I was thinking of doing this. If ResumeLayout(false) is called, but PerformLayout() has never been called, maybe its ok to call it? I hope I'm making sense. The problem is hard to explain, you really need to compile and try the test case to understand. I've really tried to solve this myself, but I'm stuck and I don't want to break or tear down PNET winforms performance from asking it to layout or draw too much. Curious if I'm on the right track or totally off. Included are the 2 files that need to be compiled to test it. If you notice, the control itself is anchoring fine, but any child controls inside the UserControl are not. Any help greatly appreciated! Thanks, Simon
TestControl.cs
(text/plain, 1.9 KB)
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace TestControl
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class TestControl : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public TestControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component 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()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.button1.Location = new System.Drawing.Point(0, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
//
// TestControl
//
this.BackColor = System.Drawing.Color.SlateGray;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Name = "TestControl";
this.Size = new System.Drawing.Size(112, 56);
this.ResumeLayout(false);
}
#endregion
}
}
Form1.cs
(text/plain, 2.1 KB)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace LayoutTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private TestControl.TestControl testControl1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#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()
{
this.testControl1 = new TestControl.TestControl();
this.SuspendLayout();
//
// testControl1
//
this.testControl1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.testControl1.BackColor = System.Drawing.Color.SlateGray;
this.testControl1.Location = new System.Drawing.Point(0, 24);
this.testControl1.Name = "testControl1";
this.testControl1.Size = new System.Drawing.Size(272, 56);
this.testControl1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(272, 107);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.testControl1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}