form load and Resize event
-
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?
I think you can change the behaviour by overriding CreateParams or setting the ControlStyles :) top secret xacc-ide 0.0.1
-
I think you can change the behaviour by overriding CreateParams or setting the ControlStyles :) top secret xacc-ide 0.0.1
I think you're thinking about repainting automatically when the form resizes. There's nothing in
CreateParams
property (it's actually the protected propertyControl.ResizeRedraw
you're thinking about in this case) orControlStyles
enumeration that controls that.Microsoft MVP, Visual C# My Articles
-
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?
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). TheOnResize
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 callbase.OnResize
(which will fire theResize
event) and don't call your code that you would normally when a form resizes.Microsoft MVP, Visual C# My Articles
-
I think you're thinking about repainting automatically when the form resizes. There's nothing in
CreateParams
property (it's actually the protected propertyControl.ResizeRedraw
you're thinking about in this case) orControlStyles
enumeration that controls that.Microsoft MVP, Visual C# My Articles
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}
-
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}
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 theControl.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