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. Constrain form to horizontal resize only?

Constrain form to horizontal resize only?

Scheduled Pinned Locked Moved C#
csharpdotnetquestion
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.
  • J Offline
    J Offline
    james cxx
    wrote on last edited by
    #1

    Can anyone suggest the best way to constrain a form to horizontal resizing only? Delegating a Resize handler doesn't work so great. If I set Height=400; in the Resize handler, it does indeed force the window to a height of 400 (or whatever you like) but when the user drags the window border, the window momentarily resizes to fit the mouse, and then the handler kicks in and pushes it back to 400 and back and forth causes a nasty flicker. I've seen some Win32 examples that process WM_NCHITTEST messages and return 0; but I don't see a way to do this with C# .NET Framework. Any ideas? -- James --

    J P 2 Replies Last reply
    0
    • J james cxx

      Can anyone suggest the best way to constrain a form to horizontal resizing only? Delegating a Resize handler doesn't work so great. If I set Height=400; in the Resize handler, it does indeed force the window to a height of 400 (or whatever you like) but when the user drags the window border, the window momentarily resizes to fit the mouse, and then the handler kicks in and pushes it back to 400 and back and forth causes a nasty flicker. I've seen some Win32 examples that process WM_NCHITTEST messages and return 0; but I don't see a way to do this with C# .NET Framework. Any ideas? -- James --

      J Offline
      J Offline
      Jim Stewart
      wrote on last edited by
      #2

      Have you looked at the MinimumSize/MaximumSize properties? You can also check for the WM_GETMINMAXINFO message.

      α.γεεκ

      Fortune passes everywhere.
      Duke Leto Atreides

      1 Reply Last reply
      0
      • J james cxx

        Can anyone suggest the best way to constrain a form to horizontal resizing only? Delegating a Resize handler doesn't work so great. If I set Height=400; in the Resize handler, it does indeed force the window to a height of 400 (or whatever you like) but when the user drags the window border, the window momentarily resizes to fit the mouse, and then the handler kicks in and pushes it back to 400 and back and forth causes a nasty flicker. I've seen some Win32 examples that process WM_NCHITTEST messages and return 0; but I don't see a way to do this with C# .NET Framework. Any ideas? -- James --

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

        set the maximumsize.Height and minimumsize.Height Form properties to 400. The user will not be able to resize the form vertically (less than 400).

        J 1 Reply Last reply
        0
        • P peenu

          set the maximumsize.Height and minimumsize.Height Form properties to 400. The user will not be able to resize the form vertically (less than 400).

          J Offline
          J Offline
          james cxx
          wrote on last edited by
          #4

          Thanks Jim Stewart and peenu for the help! :-D I see there are a lot of properties I overlooked. The MaximumSize and MinimumSize properties did the trick: this.MinimumSize = new Size (400,400); this.MaximumSize = new Size (1280,400); -- James --

          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