Adding Buttons to Wizard dynamically breaks layout

Wizard for Windows Forms Forum

Posted 2 years ago by Matthias Hess
Version: 20.1.1
Platform: .NET 4.8
Environment: Windows 10 (64-bit)
Avatar

Hello there

I hope you can help us with this pesky problem. We are using version 20.1.403.0 of Actipro Wizard. If we need to upgrade to a newer version to fix the issue, please let me know.

Problem:

We are trying to add controls dynamically to WizardPages at runtime. This breaks the layout of the pages so that the controls are moved over the header of the InnerPage.

We want our Wizard to look like this

Instead it looks like this

How to reproduce the problem:

You should be able to reproduce the problem easily with the following code snippet:

namespace WindowsFormsApp1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            ActiproSoftware.Products.ActiproLicenseManager.RegisterLicense(@"CM Informatik AG", @"XXXX-XXXX-XXXX-XXXX-XXXX");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new TestWizard());
        }
    }
    
    public class TestWizard: WizardDialogForm
    {
        public TestWizard()
        {
            this.Wizard.Pages.Add(new TestPage());
            
        }
    }

    public class TestPage : WizardPage
    {
        public TestPage()
        {
            AddButton();
           
        }

        private void AddButton()
        {
            Button b = new Button();
            b.Text = "Click me, try resizing the form to fix layout";
            b.Dock = DockStyle.Top;
            b.Click += BOnClick;
            this.Controls.Add(b);
        }

        private void BOnClick(object sender, EventArgs e)
        {
            AddButton();
        }
    }
}

Best Regards

Matthias Hess
CM Informatik AG

Comments (3)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Matthias,

Thank you for the sample code and the screenshots. Those are always a great help!

I was able to reproduce the issue in v21.1.0, but not in v21.1.1.  We fixed a scenario in v21.1.1 that was causing what you are seeing. Once I moved the sample code to target v21.1.1 or higher, the initial Wizard layout was correct and continued to display correctly as I added more buttons.

Unfortunately, the solution here will require upgrading to at least v21.1.1.

As a tip... we started publishing NuGet packages with v21.1.0, so you could also use this time to switch to NuGet and make it easier to target specific versions like this. The following link has more details about working with NuGet:

https://www.actiprosoftware.com/docs/controls/winforms/nuget

Please reach out if moving to the newer release does not fully resolve the issue you are seeing.

[Modified 2 years ago]


Actipro Software Support

Posted 2 years ago by Matthias Hess
Avatar

I tried it with v22.1.2, here is what I found.

My little demo program no longer showed the problem. However, the problem in our application still persists.

After some investigation, I found out that setting Autosize=true on the wizard page seems to trigger the error..

I updated my demo app, you should be able to reproduce the problem in v22.1.2 with the following code sample:

using System;
using System.Windows.Forms;
using ActiproSoftware.UI.WinForms.Controls.Wizard;


namespace WindowsFormsApp1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
           
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new TestWizard());
        }
    }
    
    public class TestWizard: WizardDialogForm
    {
        public TestWizard()
        {
            this.Wizard.Pages.Add(new TestPage());
            
        }
    }

    public class TestPage : WizardPage
    {
        public TestPage()
        {
            this.AutoSize = true; // REMOVE THIS LINE AND THE BUG DISAPPEARS
            AddButton();
            
        }

        private void AddButton()
        {
            Button b = new Button();
            b.Text = "Click me, try resizing the form to fix layout";
            b.Dock = DockStyle.Top;
            b.Click += BOnClick;
            this.Controls.Add(b);
        }

        private void BOnClick(object sender, EventArgs e)
        {
            AddButton();
           
        }
    }
    
    
}

[Modified 2 years ago]

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Thank you for the follow-up. With the AutoSize setting in place I was able to reproduce the issue and add a fix for the next maintenance release that will improve positioning of interior pages when any layout change occurs.

Having said that, it is worth noting that the size of Wizard is dictated by the Wizard control itself, not the WizardPage instances displayed on the Wizard. Any direct changes to the bounds of a WizardPage will be overwritten the next time Wizard performs a layout update, so using the WizardPage.AutoSize property is not recommended.


Actipro Software Support

The latest build of this product (v24.1.0) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.