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 load and Resize event

form load and Resize event

Scheduled Pinned Locked Moved C#
question
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.
  • A Offline
    A Offline
    ABean
    wrote on last edited by
    #1

    I have a Resize method that I want called only when the user changes the size of the form. But when I Load that form for the first time I notice that the resize event gets called. Is there some way to prevent this?

    L H 2 Replies Last reply
    0
    • A ABean

      I have a Resize method that I want called only when the user changes the size of the form. But when I Load that form for the first time I notice that the resize event gets called. Is there some way to prevent this?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      I think you can change the behaviour by overriding CreateParams or setting the ControlStyles :) top secret xacc-ide 0.0.1

      H 1 Reply Last reply
      0
      • L leppie

        I think you can change the behaviour by overriding CreateParams or setting the ControlStyles :) top secret xacc-ide 0.0.1

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        I think you're thinking about repainting automatically when the form resizes. There's nothing in CreateParams property (it's actually the protected property Control.ResizeRedraw you're thinking about in this case) or ControlStyles enumeration that controls that.

        Microsoft MVP, Visual C# My Articles

        L 1 Reply Last reply
        0
        • A ABean

          I have a Resize method that I want called only when the user changes the size of the form. But when I Load that form for the first time I notice that the resize event gets called. Is there some way to prevent this?

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          It is being resized when the form loads. It starts out as a zero-width and zero-height window and then is drawn in the appropriate dimensions, hence the resize. The solution is simple: use a state variable (recommend private accessibility). It's initially unset (false, for example) and the OnLoad override will set it (true, for example). The OnResize handler (btw - don't handle events from a base class in a derivative class: it's inefficient and gives you less control) will check this state variable. If it's unset, don't call base.OnResize (which will fire the Resize event) and don't call your code that you would normally when a form resizes.

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          • H Heath Stewart

            I think you're thinking about repainting automatically when the form resizes. There's nothing in CreateParams property (it's actually the protected property Control.ResizeRedraw you're thinking about in this case) or ControlStyles enumeration that controls that.

            Microsoft MVP, Visual C# My Articles

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            public enum ControlStyles
            {
            // Fields
            AllPaintingInWmPaint = 8192,
            CacheText = 16384,
            ContainerControl = 1,
            DoubleBuffer = 65536,
            EnableNotifyMessage = 32768,
            **FixedHeight = 64,
            FixedWidth = 32,**Opaque = 4,
            ResizeRedraw = 16,
            Selectable = 512,
            StandardClick = 256,
            StandardDoubleClick = 4096,
            SupportsTransparentBackColor = 2048,
            UserMouse = 1024,
            UserPaint = 2

            }

            :) top secret xacc-ide 0.0.1

            H 1 Reply Last reply
            0
            • L leppie

              public enum ControlStyles
              {
              // Fields
              AllPaintingInWmPaint = 8192,
              CacheText = 16384,
              ContainerControl = 1,
              DoubleBuffer = 65536,
              EnableNotifyMessage = 32768,
              **FixedHeight = 64,
              FixedWidth = 32,**Opaque = 4,
              ResizeRedraw = 16,
              Selectable = 512,
              StandardClick = 256,
              StandardDoubleClick = 4096,
              SupportsTransparentBackColor = 2048,
              UserMouse = 1024,
              UserPaint = 2

              }

              :) top secret xacc-ide 0.0.1

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              He doesn't want a fixed-width form, merely to not be notified initially of the resize when the form is loading. You did, however, remind me that it was ControlStyles.ResizeRedraw and the Control.ResizeRedraw property that did match-up, though. I knew there was a pairing there somewhere, just didn't remember off the top of my head.

              Microsoft MVP, Visual C# My Articles

              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