ury

Hi,

I would like to force the invokation of the OnResize event handler of a control.

Currently I use (please forgive me) the following code:

Code Snippet

Parent.SuspendLayout();

Parent.Height++;

Parent.Height--;

Parent.ResumeLayout();

Any better suggestions
Thanks,
Ury


Re: Windows Forms General Force invoking the OnResize event handler

nobugz

Yes, that's ugly. Add an event to your control and let the parent subscribe to it. Moved to Windows Forms General.





Re: Windows Forms General Force invoking the OnResize event handler

ury

Thanks, but this is exactly what I would like to avoid (the need to add additional code at the parent control).

The case in question is a custom control which changes its height when an object is bound to it. I would like to trigger the contianer (parent) control's OnResize handler when this occurs. As there are multiple such controls, I would like to do it at the custom control's code (once) and not in the parent controls (many many...).





Re: Windows Forms General Force invoking the OnResize event handler

nobugz

Why does the parent's OnResize() method have to run when it is you that changes your size





Re: Windows Forms General Force invoking the OnResize event handler

ury

Short: It doesn't *have* to run. It's just extremely nice to have the parent automatically resize itself once its child control is resized.

Long: my control reflects the properties of its bound object. When I change the bound object, the size of this list may change. I want to resize the container control too. Some of the parent controls (which don't always contain such a "reflector" control, and vice versa) already have an automatic resizing code in the OnResize handler, and I would like to reuse it.





Re: Windows Forms General Force invoking the OnResize event handler

nobugz

I don't get it. They resize themselves in their OnResize() method That's a chicken-and-egg problem. They need to subscribe to your Resize event, not their own.





Re: Windows Forms General Force invoking the OnResize event handler

ury

Sorry I wasn't clear:

Maybe the following pseudo-code can clarify:

Code Snippet

class ContainterPanel

{

// some *special* super-panel functionality

}

class ReflectorGadget

{

private object boundObject;

public object BoundObject

{

get

{

boundObject = BoundObject;

/*

* build the UI of the ReflectorGadget here, resulting in resizing

* itself (the ReflectorGadget control) according to the number of

* the properties in the reflected (bound) object

*/

/*

* this is where I want to force the parent

* control's OnResize invocation

*/

}

}

}

In my main form, I have several ContainerPanel objects, some contain ReflectorGadget controls, some don't. Each of these panel objects has its own elaborate resizing code (which is too specific to reside in the class code).

When in my code I set reflectorGadgetXYZ,BoundObject = objectABC, I want to execute the aforementioned resizing code. This will fit the newly-resized reflectorGadgetXYZ in its parent ContainerPanel.

The thing is that the ContainerPanel resizing is specific to each control, while the invocation of BoundObject is in the class-level code.

I hope it's clearer now.