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. Form Resizing Problems

Form Resizing Problems

Scheduled Pinned Locked Moved C#
csharphelp
6 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.
  • P Offline
    P Offline
    PhilDanger
    wrote on last edited by
    #1

    Hey everyone, first time poster here. I'm working on a C# project where I need an image and things drawn on top of the image to automatically scale to the size of the form when the user does the following options: manual resize, maximize, restore from maximize. The user can also use a zoom tool, and when this happens scroll bars for panning the image appear and the actual size of the form is not changed. I've got some event handlers attached to the form's Resize and ResizeEnd events to control the automatic scaling, but I've run into a few problems: 1. ResizeEnd gets called when I drag and drop the form, meaning the image and objects on it are automatically scaled, so if the user has used the zoom tool to zoom in, this gets overridden by the resize. 2. I need to make it so that automatic resizing is not done on a minimize or a restore from a minimize, for the same reason as #1 -- a manually zoomed image should stay manually zoomed. I tried to override WndProc to filter out certain ones, but to no avail. Any help or guidance would be appreciated, thanks!

    D L 2 Replies Last reply
    0
    • P PhilDanger

      Hey everyone, first time poster here. I'm working on a C# project where I need an image and things drawn on top of the image to automatically scale to the size of the form when the user does the following options: manual resize, maximize, restore from maximize. The user can also use a zoom tool, and when this happens scroll bars for panning the image appear and the actual size of the form is not changed. I've got some event handlers attached to the form's Resize and ResizeEnd events to control the automatic scaling, but I've run into a few problems: 1. ResizeEnd gets called when I drag and drop the form, meaning the image and objects on it are automatically scaled, so if the user has used the zoom tool to zoom in, this gets overridden by the resize. 2. I need to make it so that automatic resizing is not done on a minimize or a restore from a minimize, for the same reason as #1 -- a manually zoomed image should stay manually zoomed. I tried to override WndProc to filter out certain ones, but to no avail. Any help or guidance would be appreciated, thanks!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      PhilDanger wrote:

      I've got some event handlers attached to the form's Resize and ResizeEnd events to control the automatic scaling, but I've run into a few problems: 1. ResizeEnd gets called when I drag and drop the form, meaning the image and objects on it are automatically scaled, so if the user has used the zoom tool to zoom in, this gets overridden by the resize. 2. I need to make it so that automatic resizing is not done on a minimize or a restore from a minimize, for the same reason as #1 -- a manually zoomed image should stay manually zoomed. I tried to override WndProc to filter out certain ones, but to no avail.

      If I understand the problem, you don't have to do this. All you need to do is check the status of the form's WindowState property. If it's Normal or Maximized, do your scaling as normal. Otherwise, skip the scaling.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      P 1 Reply Last reply
      0
      • D Dave Kreskowiak

        PhilDanger wrote:

        I've got some event handlers attached to the form's Resize and ResizeEnd events to control the automatic scaling, but I've run into a few problems: 1. ResizeEnd gets called when I drag and drop the form, meaning the image and objects on it are automatically scaled, so if the user has used the zoom tool to zoom in, this gets overridden by the resize. 2. I need to make it so that automatic resizing is not done on a minimize or a restore from a minimize, for the same reason as #1 -- a manually zoomed image should stay manually zoomed. I tried to override WndProc to filter out certain ones, but to no avail.

        If I understand the problem, you don't have to do this. All you need to do is check the status of the form's WindowState property. If it's Normal or Maximized, do your scaling as normal. Otherwise, skip the scaling.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        P Offline
        P Offline
        PhilDanger
        wrote on last edited by
        #3

        Hi Dave, Could you clarify this a bit more for me, are you suggesting that I check the WindowState in the Resize(End) handlers? If this is in fact the idea, I still am left with a few problems -- the form drag still calls the ResizeEnd event, which will force an automatic resize even which the state check in there since the Form will be Normal, and when I restore from a minimize, the Resize event is fired AFTER the form restores itself, so although it won't resize when it minimizes, it will resize when it is restored). Thanks for the start.

        1 Reply Last reply
        0
        • P PhilDanger

          Hey everyone, first time poster here. I'm working on a C# project where I need an image and things drawn on top of the image to automatically scale to the size of the form when the user does the following options: manual resize, maximize, restore from maximize. The user can also use a zoom tool, and when this happens scroll bars for panning the image appear and the actual size of the form is not changed. I've got some event handlers attached to the form's Resize and ResizeEnd events to control the automatic scaling, but I've run into a few problems: 1. ResizeEnd gets called when I drag and drop the form, meaning the image and objects on it are automatically scaled, so if the user has used the zoom tool to zoom in, this gets overridden by the resize. 2. I need to make it so that automatic resizing is not done on a minimize or a restore from a minimize, for the same reason as #1 -- a manually zoomed image should stay manually zoomed. I tried to override WndProc to filter out certain ones, but to no avail. Any help or guidance would be appreciated, thanks!

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, the way I see it you have three input variables: size, zoom and pan. They are state variables in your sizing/zooming/panning problem. whenever one of them changes, you must recalculate and adapt things. So I would suggest you create one method that takes size, zoom and pan as input parameters and does whatever needs to be done; now all your handlers related to changing either size, zoom or pan should call that one function. You probably are not keeping size information in your own variables; that's OK. But that probably it is also what confuses you, since no one is holding your zoom/pan information for you, and its my guess that is at the heart of your problem. Anyway, I concur with Dave; there is no need to fiddle with WndProc here. Hope this helps. :)

          Luc Pattyn [My Articles] [Forum Guidelines]

          P 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, the way I see it you have three input variables: size, zoom and pan. They are state variables in your sizing/zooming/panning problem. whenever one of them changes, you must recalculate and adapt things. So I would suggest you create one method that takes size, zoom and pan as input parameters and does whatever needs to be done; now all your handlers related to changing either size, zoom or pan should call that one function. You probably are not keeping size information in your own variables; that's OK. But that probably it is also what confuses you, since no one is holding your zoom/pan information for you, and its my guess that is at the heart of your problem. Anyway, I concur with Dave; there is no need to fiddle with WndProc here. Hope this helps. :)

            Luc Pattyn [My Articles] [Forum Guidelines]

            P Offline
            P Offline
            PhilDanger
            wrote on last edited by
            #5

            Hi Luc, Thanks for the suggestions, I'll look into it. In the mean time, I implemented a hasty fix that of course has it's own drawbacks. The image was actually residing in a PictureBox that was inside a Panel, and the panel controlled scrolling when the PictureBox got too big to fit... instead of using the Form's Resize event, I instead hooked up a handler to the panel's Resize. This work fine except for the fact that the panel fired off a Resize when scroll bars were added. The fix to this was just to put everything in ANOTHER panel and use that one's Resize event to handle automatic resizing. The drawback of this however, is that a Panel doesn't have ResizeBegin or ResizeEnd events -- I was scaling the image every half a second it was being resized so that it wasn't doing an expensive resize 20 times a second and then doing one final resize on the ResizeEnd. With the new "fix", I can stop resizing between the times when it is making the new scaled image, and it won't fit properly (just a bit off). Now to investigate this one! Thanks again, Phil

            L 1 Reply Last reply
            0
            • P PhilDanger

              Hi Luc, Thanks for the suggestions, I'll look into it. In the mean time, I implemented a hasty fix that of course has it's own drawbacks. The image was actually residing in a PictureBox that was inside a Panel, and the panel controlled scrolling when the PictureBox got too big to fit... instead of using the Form's Resize event, I instead hooked up a handler to the panel's Resize. This work fine except for the fact that the panel fired off a Resize when scroll bars were added. The fix to this was just to put everything in ANOTHER panel and use that one's Resize event to handle automatic resizing. The drawback of this however, is that a Panel doesn't have ResizeBegin or ResizeEnd events -- I was scaling the image every half a second it was being resized so that it wasn't doing an expensive resize 20 times a second and then doing one final resize on the ResizeEnd. With the new "fix", I can stop resizing between the times when it is making the new scaled image, and it won't fit properly (just a bit off). Now to investigate this one! Thanks again, Phil

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi Phil, the ResizeBegin/End events are new to me; I did most of my work in 1.1 compatible way. And I avoid using PictureBoxes, they are not worth the trouble in my opinion. When a panel suddenly shows/hides one or both scrollbars, naturally that affects the remaining "clientsize". For that reason, I do what you ar doing now, I think, that is having a non-scrolling (but moving) panel inside a scrolling panel. You probably can give your panel a ResizeBegin/End functionality by hooking them to the form; so you could disable your panel resize logic while the form is between ResizeBegin and End (unless you want ways to resize the panel without resizing the form...). BTW, I read in the doc that ResizeBegin/End also fires when you MOVE the form. Cheers.

              Luc Pattyn [My Articles] [Forum Guidelines]

              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