C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,194 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How do I detect when screen is sized(minimize is used).
Here you go
using System;
using System.Security.Permissions;
using System.Windows.Forms;
namespace Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Resize += OnResize;
}
private void OnResize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Console.WriteLine(nameof(OnResize));
}
}
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MINIMIZE = 0xF020;
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_SYSCOMMAND:
int command = m.WParam.ToInt32() & 0xfff0;
if (command == SC_MINIMIZE)
{
Console.WriteLine(nameof(WndProc));
}
// If you don't want to do the default action then break
break;
}
base.WndProc(ref m);
}
}
}