็ธฆๆจชๆฏ”ใ‚’็ถญๆŒใ—ใŸใพใพใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใ‚ตใ‚คใ‚บใ‚’ๅค‰ๆ›ดใ™ใ‚‹ๆ–นๆณ•

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

// ใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใ‚ตใ‚คใ‚บๅค‰ๆ›ดใ‚คใƒ™ใƒณใƒˆ
protected override void WndProc(ref System.Windows.Forms.Message m)
{
ใ€€ใ€€this.AspectRatioSizeWndProc(ref m, 4 / 3, true);
ใ€€ใ€€base.WndProc(ref m);
}

private struct WmRect
{
ใ€€ใ€€public int Left;
ใ€€ใ€€public int Top;
ใ€€ใ€€public int Right;
ใ€€ใ€€public int Bottom;
ใ€€ใ€€
ใ€€ใ€€public static implicit operator Rectangle(WmRect r)
ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€return new Rectangle(r.Left, r.Top, r.Right – r.Left, r.Bottom – r.Top);
ใ€€ใ€€}
ใ€€ใ€€
ใ€€ใ€€public static implicit operator WmRect(Rectangle r)
ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€return new WmRect
ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Top = r.Top,
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Bottom = r.Bottom,
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Left = r.Left,
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Right = r.Right
ใ€€ใ€€ใ€€ใ€€};
ใ€€ใ€€}
ใ€€ใ€€
ใ€€ใ€€public override string ToString()
ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€return string.Format(
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€”Left {0}, Top {1}, Right {2}, Bottom {3}”,
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€this.Left.ToString(),
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€this.Top.ToString(),
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€this.Right.ToString(),
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€this.Bottom.ToString());
ใ€€ใ€€}
}

public enum WmSz
{
ใ€€ใ€€Left = 1,
ใ€€ใ€€Right = 2,
ใ€€ใ€€Top = 3,
ใ€€ใ€€Bottom = 6,
ใ€€ใ€€
ใ€€ใ€€TopLeft = Top + Left,
ใ€€ใ€€TopRight = Top + Right,
ใ€€ใ€€BottomLeft = Bottom + Left,
ใ€€ใ€€BottomRight = Bottom + Right,
}

///

/// ใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใƒปใƒ—ใƒญใ‚ทใƒผใ‚ธใƒฃๅ†…ใงๅ‘ผใณๅ‡บใ™ใ“ใจใงใ€
/// ใƒžใ‚ฆใ‚นใงใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใฎ็ธใ‚’ใƒ‰ใƒฉใƒƒใ‚ฐใ—ใฆใƒ•ใ‚ฉใƒผใƒ ใฎใ‚ตใ‚คใ‚บใ‚’ๅค‰ๆ›ดใ—ใŸใจใใซใ€
/// ใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใ‚ตใ‚คใ‚บใŒๆŒ‡ๅฎšใ—ใŸใ‚ขใ‚นใƒšใ‚ฏใƒˆๆฏ”ใ‚’็ถญๆŒใ™ใ‚‹ใ‚ˆใ†ใซใชใ‚‹ใ€‚
///

/// ใ‚ตใ‚คใ‚บใŒๅค‰ๆ›ดใ•ใ‚Œใ‚‹ใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆ /// ใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใƒปใƒ—ใƒญใ‚ทใƒผใ‚ธใƒฃใซๆธกใ•ใ‚ŒใŸWindowsใƒกใƒƒใ‚ปใƒผใ‚ธ /// ใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใ‚ตใ‚คใ‚บใฎใ‚ขใ‚นใƒšใ‚ฏใƒˆๆฏ”๏ผˆๅน…/้ซ˜ใ•๏ผ‰ /// ใ‚ฏใƒฉใ‚คใ‚ขใƒณใƒˆ้ ˜ๅŸŸใฎใ‚ขใ‚นใƒšใ‚ฏใƒˆๆฏ”ใ‚’ไธ€ๅฎšใซไฟใคใ‚ˆใ†ใซใ™ใ‚‹ๅ ดๅˆใฏtrueใ€‚
/// falseใ‚’ๆŒ‡ๅฎšใ™ใ‚‹ใจใ€ใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใฎๅขƒ็•Œ็ทšใ‚„ใ‚ฟใ‚คใƒˆใƒซใƒใƒผใ‚‚ๅซใ‚ใŸใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆๅ…จไฝ“ใฎใ‚ตใ‚คใ‚บใฎใ‚ขใ‚นใƒšใ‚ฏใƒˆๆฏ”ใ‚’ไฟใคใ‚ˆใ†ใซใ™ใ‚‹ใ€‚>
public static void AspectRatioSizeWndProc(this Form form, ref Message m, float aspect, bool clientSize)
{
ใ€€ใ€€const int WM_SIZING = 0x214;
ใ€€ใ€€
ใ€€ใ€€if (m.Msg == WM_SIZING)
ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€if (aspect > 0f)
ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€//็”ป้ขไธŠใงใฎใ€ใ‚ฆใ‚ฃใƒณใƒ‰ใ‚ฆใฎไธŠไธ‹ๅทฆๅณใฎๅบงๆจ™
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€WmRect rc = (WmRect)Marshal.PtrToStructure(m.LParam, typeof(WmRect));
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€WmSz res = (WmSz)m.WParam.ToInt32();
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€switch (res)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€case WmSz.Left:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€case WmSz.Right:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int w = rc.Right – rc.Left;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int h;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€if (clientSize)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Size borders = Size.Subtract(form.Size, form.ClientSize);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€w -= borders.Width;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€h = (int)(w / aspect) + borders.Height;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€else
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€h = (int)(w / aspect);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€rc.Bottom = rc.Top + h;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Marshal.StructureToPtr(rc, m.LParam, true);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€break;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€case WmSz.Top:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€case WmSz.Bottom:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int h = rc.Bottom – rc.Top;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int w;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€if (clientSize)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Size borders = Size.Subtract(form.Size, form.ClientSize);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€h -= borders.Height;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€w = (int)(h * aspect) + borders.Width;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€else
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€w = (int)(h * aspect);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€rc.Right = rc.Left + w;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€break;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€case WmSz.TopLeft:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€case WmSz.TopRight:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int recW = rc.Right – rc.Left;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int recH = rc.Bottom – rc.Top;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int w, h;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€if (clientSize)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Size borders = Size.Subtract(form.Size, form.ClientSize);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€recW -= borders.Width;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€recH -= borders.Height;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€w = (int)(recH * aspect) + borders.Width;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€h = (int)(recW / aspect) + borders.Height;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€else
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€w = (int)(recH * aspect);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€h = (int)(recW / aspect);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int dh = recW * recW + h * h;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int dw = recH * recH + w * w;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€if (dh > dw)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€rc.Top = rc.Bottom – h;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€else
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€if (res == WmSz.TopLeft)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€rc.Left = rc.Right – w;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€else if (res == WmSz.TopRight)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€rc.Right = rc.Left + w;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€break;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€case WmSz.BottomLeft:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€case WmSz.BottomRight:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int recW = rc.Right – rc.Left;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int recH = rc.Bottom – rc.Top;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int w, h;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€if (clientSize)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Size borders = Size.Subtract(form.Size, form.ClientSize);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€recW -= borders.Width;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€recH -= borders.Height;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€w = (int)(recH * aspect) + borders.Width;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€h = (int)(recW / aspect) + borders.Height;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€else
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€w = (int)(recH * aspect);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€h = (int)(recW / aspect);
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int dh = recW * recW + h * h;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€int dw = recH * recH + w * w;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€if (dh > dw)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€rc.Bottom = rc.Top + h;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€else
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€if (res == WmSz.BottomLeft)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€rc.Left = rc.Right – w;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€else if (res == WmSz.BottomRight)
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€{
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€rc.Right = rc.Left + w;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€break;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€default:
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€break;
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€Marshal.StructureToPtr(rc, m.LParam, true);
ใ€€ใ€€ใ€€ใ€€}
ใ€€ใ€€}
}

Follow me!