Full size Windows Forms app have issues on Windows 11

Copper Contributor

I have developed a full screen application for Windows using .NET 6.0. It works fine on Windows 10 but there are two problems when running on Windows 11. The first one is that the first time there is a come back to a previous form using

 

 

 

BackForm.Show()
Hide()

 

 

 

The application hides itself. After that, it does not happen again, until the application is closed and started again.

 

The other problem on Windows 11 is that there is a form that does not grows well to cover the full screen. It is the only form, and it is characterized for having a DateTimePicker, a ComboBox, and a ListView. All forms inherit from FullSizeForm, which includes the following code:

 

 

 

public partial class FullSizeForm : Form {
    private Rectangle LastFormSize;

    protected FullSizeForm() {
        AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
        AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        ClientSize = new System.Drawing.Size(800, 450);
        LastFormSize = new Rectangle(Location.X, Location.Y, Width, Height);
    }

    protected void FullSizeForm_Load(object sender, EventArgs e) {
        MaximizeBox = false;
        MinimizeBox = false;
        ControlBox = false;
        VerticalScroll.Visible = false;
        VerticalScroll.Enabled = false;
        FormBorderStyle = FormBorderStyle.None;
        WindowState = FormWindowState.Maximized;
    }

    protected void FullSizeForm_Resize(object sender, EventArgs e) {
        float xRatio = (float)Width / LastFormSize.Width;
        float yRatio = (float)Height / LastFormSize.Height;
        float ratio = xRatio < yRatio ? xRatio : yRatio;
        foreach (Control c in Controls) {
            ResizeControl(c, ratio);
        }
        float newWidth = LastFormSize.Width * ratio;
        float newHeight = LastFormSize.Height * ratio;
        LastFormSize = new Rectangle(Location.X, Location.Y, (int)newWidth, (int)newHeight);
    }

    protected void ResizeControl(Control control, float ratio) {
        int newX = (int)(control.Location.X * ratio);
        int newY = (int)(control.Location.Y * ratio);
        int newWidth = (int)(control.Width * ratio);
        int newHeight = (int)(control.Height * ratio);
        control.Location = new Point(newX, newY);
        control.Size = new Size(newWidth, newHeight);
        float newFSize = (control.Font.Size * ratio);
        control.Font = new Font(control.Font.Name, newFSize, control.Font.Style);
        if (control is ListView listView) {
            foreach (ColumnHeader header in listView.Columns) {
                int width = header.Width;
                width = (int)(width * ratio);
                header.Width = width;
            }
        }
        foreach (Control c in control.Controls)
            ResizeControl(c, ratio);
    }
}

 

 

 

As I said before, the code works fine on Windows 10, but fails on Windows 11 (some buttons lose their texts, as I guess it gets too large) on that particular form.

 

Any help would be greatly appreciated.

 

 

 

2 Replies

Hi @LaSaltena,

Thanks for posting your issue here.

However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
Best Regards,
Lan Huang

@LanHuangSorry my mistake. I will ask support there, and let you know the results.