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 8714317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:34:07+00:00 2026-06-13T05:34:07+00:00

I want to cancel the natural minimizing behavior and change a WPF form size

  • 0

I want to cancel the natural minimizing behavior and change a WPF form size instead.

I have a solution with the Window_StateChanged but it doesn’t look so nice – the window first minimized then jumps back and does the size alteration. Is there a way to accomplish this? I Googled for Window_StateChanging but couldn’t figure it out, some sort of external lib that I prefer not to use.

That’s what I have:

private void Window_StateChanged(object sender, EventArgs e)
{
    switch (this.WindowState)
    {
        case WindowState.Minimized:
            {
                WindowState = System.Windows.WindowState.Normal;
                this.Width = 500;
                this.Height = 800;
                break;
            }
    }
}

Thanks,

EP

  • 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-06-13T05:34:08+00:00Added an answer on June 13, 2026 at 5:34 am

    You’ll need to intercept the minimize command before your form fires Window_StateChanged, to avoid the minimize/restore dance you’re seeing. I believe the easiest way to do this is to have your form listen for Windows messages and when the minimize command is received, cancel it and resize your form.

    Register the SourceInitialized event, in your form constructor:

    this.SourceInitialized += new EventHandler(OnSourceInitialized); 
    

    Add these two handlers to your form:

    private void OnSourceInitialized(object sender, EventArgs e) {
        HwndSource source = (HwndSource)PresentationSource.FromVisual(this);
        source.AddHook(new HwndSourceHook(HandleMessages));
    } 
    
    private IntPtr HandleMessages(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
        // 0x0112 == WM_SYSCOMMAND, 'Window' command message.
        // 0xF020 == SC_MINIMIZE, command to minimize the window.
        if (msg == 0x0112 && ((int)wParam & 0xFFF0) == 0xF020) {
            // Cancel the minimize.
            handled = true;
    
            // Resize the form.
            this.Width = 500;
            this.Height = 500;
        }
    
        return IntPtr.Zero;
    } 
    

    I suspect this is the approach you were hoping to avoid but boiled down to the code I show it’s not too difficult to implement.

    Code based on this SO question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have VS 2010 and want to cancel the form closing event via a
I want to change the title of the search bar cancel button to Offers
I have several thread pools and I want my application to handle a cancel
I have been using ASIHTTPRequest to fetch the data and i want to cancel
I want have an insert query, but before inserting I check whether the username
In my app,I want to cancel the old toast ,and show the new toast.But
I'm submitting a form with JS and I want to cancel the submit if
I have a ProgressMonitor pm and a SwingWorker sw . I want to cancel
I have a form with two buttons, a submit button and a cancel/close button.
I have an ASP.NET form with a cancel button that is supposed to, after

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.