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. LocationChanged to set windowstate=Maximized

LocationChanged to set windowstate=Maximized

Scheduled Pinned Locked Moved C#
question
4 Posts 3 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
    Member 8302920
    wrote on last edited by
    #1

    How do I implement a Window app to maximize when user moves the window from one display monitor to another. When the move occurs LocationChanged event is triggered and the window state becomes Normal. I tried this.WindowState=FormWindowState.Maximized in the LocationChanged handler. However, the window does not maximized. Likely because it triggered circular reference. I had also implemented a module Boolean variable to avoid this. However, the window never maximized. What is the proper way to implement this? Thank you in advance for your response.

    M A 2 Replies Last reply
    0
    • M Member 8302920

      How do I implement a Window app to maximize when user moves the window from one display monitor to another. When the move occurs LocationChanged event is triggered and the window state becomes Normal. I tried this.WindowState=FormWindowState.Maximized in the LocationChanged handler. However, the window does not maximized. Likely because it triggered circular reference. I had also implemented a module Boolean variable to avoid this. However, the window never maximized. What is the proper way to implement this? Thank you in advance for your response.

      M Offline
      M Offline
      Midi_Mick
      wrote on last edited by
      #2

      While the mouse button is down, as far as the system is concerned, the window is still moving. I would look at setting a flag in the LocationChanged event to let you know that the window is moving, and then set the FormWindowState in the MouseUp event (and then resetting that flag too, of course).

      Cheers, Mick ------------------------------------------------ It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.

      1 Reply Last reply
      0
      • M Member 8302920

        How do I implement a Window app to maximize when user moves the window from one display monitor to another. When the move occurs LocationChanged event is triggered and the window state becomes Normal. I tried this.WindowState=FormWindowState.Maximized in the LocationChanged handler. However, the window does not maximized. Likely because it triggered circular reference. I had also implemented a module Boolean variable to avoid this. However, the window never maximized. What is the proper way to implement this? Thank you in advance for your response.

        A Offline
        A Offline
        Alan N
        wrote on last edited by
        #3

        I think the ResizeBegin and ResizeEnd events will help you. The naming is misleading as the purpose of these events is to indicate when the form is showing the resizing border. Click and hold on the form border or caption bar and the ResizeBegin event is raised. ResizeEnd is seen on release whether or not any resizing has occurred. Here is a trivial (and annoying) modification to a form to make it maximise when it is moved without having changed it's size.

        private Rectangle? lastBounds;
        
        protected override void OnResizeBegin(EventArgs e) {
          base.OnResizeBegin(e);
          System.Diagnostics.Debug.Print("EVENT ResizeBegin");
          lastBounds = Bounds;
        }
        
        protected override void OnResizeEnd(EventArgs e) {
          base.OnResizeBegin(e);
          System.Diagnostics.Debug.Print("EVENT ResizeEnd");
          if (lastBounds.HasValue) {
            Rectangle previous = lastBounds.Value;
            // Maximise when moved without resizing
            if (previous != Bounds && previous.Size == Bounds.Size) {
              WindowState = FormWindowState.Maximized;
            }
            lastBounds = null;
          }
        }
        

        In your case it would be necessary to detect the System.Windows.Forms.Screen containing the form in ResizeBegin and test for the desired destination Screen in ResizeEnd. Alan.

        M 1 Reply Last reply
        0
        • A Alan N

          I think the ResizeBegin and ResizeEnd events will help you. The naming is misleading as the purpose of these events is to indicate when the form is showing the resizing border. Click and hold on the form border or caption bar and the ResizeBegin event is raised. ResizeEnd is seen on release whether or not any resizing has occurred. Here is a trivial (and annoying) modification to a form to make it maximise when it is moved without having changed it's size.

          private Rectangle? lastBounds;
          
          protected override void OnResizeBegin(EventArgs e) {
            base.OnResizeBegin(e);
            System.Diagnostics.Debug.Print("EVENT ResizeBegin");
            lastBounds = Bounds;
          }
          
          protected override void OnResizeEnd(EventArgs e) {
            base.OnResizeBegin(e);
            System.Diagnostics.Debug.Print("EVENT ResizeEnd");
            if (lastBounds.HasValue) {
              Rectangle previous = lastBounds.Value;
              // Maximise when moved without resizing
              if (previous != Bounds && previous.Size == Bounds.Size) {
                WindowState = FormWindowState.Maximized;
              }
              lastBounds = null;
            }
          }
          

          In your case it would be necessary to detect the System.Windows.Forms.Screen containing the form in ResizeBegin and test for the desired destination Screen in ResizeEnd. Alan.

          M Offline
          M Offline
          Member 8302920
          wrote on last edited by
          #4

          Hi Mick, Alan MouseUp and ResizeBegin/End works wonderfully. Thank you and Happy New Year.

          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