Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 968733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:31:50+00:00 2026-05-16T02:31:50+00:00

How can I make a form have a fixed aspect ratio that is preserved

  • 0

How can I make a form have a fixed aspect ratio that is preserved when it is resized?

I know it can be done by overriding OnSizeChanged and manually modifying the [new] Height/Width, but that causes flicker since it is resized once before the event is called (to a size not matching the aspect ratio) and then resized again (to the correct aspect ratio). Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:31:51+00:00Added an answer on May 16, 2026 at 2:31 am

    Some code to get you started. The key is to respond to the WM_SIZING message, it allows you to change the window rectangle. This sample is crude, you really want to pay attention to which corner or edge is being dragged by the user, available from m.WParam. The user interface will never be great, you can’t really do anything reasonable when the user drags a corner. Making your form’s layout flexible enough so you don’t care about aspect ration is the real solution. Displaying a scrollbar when the content doesn’t fit pretty much lets the user do the Right Thing automatically.

    using System.Runtime.InteropServices;
    // etc..
    
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        protected override void WndProc(ref Message m) {
            if (m.Msg == 0x216 || m.Msg == 0x214) { // WM_MOVING || WM_SIZING
                // Keep the window square
                RECT rc = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
                int w = rc.Right - rc.Left;
                int h = rc.Bottom - rc.Top;
                int z = w > h ? w : h;
                rc.Bottom = rc.Top + z;
                rc.Right = rc.Left + z;
                Marshal.StructureToPtr(rc, m.LParam, false);
                m.Result = (IntPtr)1;
                return;
            }
            base.WndProc(ref m);
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct RECT {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make a HTTP PUT request in Perl that contains application/x-www-form-urlencoded data?
To make a poll form using an applet, i wanted to know how can
I have a treeview with a fixed size. How can i make it scrollable
So GET forms make the usual urls like .../search/?q=apple Can you make a form
How can I make my jQuery multi-stage form fade out on successful submission and
i am trying to make a c# WPF form where i can drag it
How can make a link within a facebox window that redirects it to another
I can make a log in for easily, so that's not the problem. What
I have a standard TStringGrid on a form. I have one Fixed Row in
I have an edit form that I'm displaying as an overlay using Jquery Tools.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.