Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Trapping windows app minimize functionality

Trapping windows app minimize functionality

Scheduled Pinned Locked Moved C#
csharpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Manster
    wrote on last edited by
    #1

    Hi all, Can anyone tell me how I can trap the event of minimizing and closing a C# windows appliction? I'm only referring to when the user hits the minimize or close button on the form's control box. I need to set a flag for my application to do something when this event occurs and I'm not sure how. Thanks ;)

    A 1 Reply Last reply
    0
    • M Manster

      Hi all, Can anyone tell me how I can trap the event of minimizing and closing a C# windows appliction? I'm only referring to when the user hits the minimize or close button on the form's control box. I need to set a flag for my application to do something when this event occurs and I'm not sure how. Thanks ;)

      A Offline
      A Offline
      apferreira
      wrote on last edited by
      #2

      Regarding the closing event, you should use the OnClosing event handler:

      private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
      {
      //TODO: Add custom code here
      }

      As for the minimizing event, Windows Forms does not have a prefedined event that handles just the minimizing of the form but you can circumvent that by using the following code:

      protected override void OnResize(EventArgs e)
      {
      if (this.WindowState == FormWindowState.Minimized)
      {
      //TODO: Add custom code here
      }

      }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups