Possible Duplicate:
“ResizeEnd” equivalent for usercontrols
I feel stupid, but I can’t find a solution to a problem that I think it’s easy.
I have a user control that (basically) shows an image drawing it during onPaint stage:
protected override void OnPaint(PaintEventArgs e)
{
if (img != null)
e.Graphics.DrawImage(img, ...);
}
When user control is resized, it must perform many actions and one is (given a particular condition) resize image to fit width or height, etc…
Image showed can be “heavy”, so when user start resizing and moves mouse, the result is a sort of slow movement that’s not good for end user.
So I’m wondering if there are windows messages reporting me that the resize operation is starting or completed: if so I can stop redrawing when resize starts and repaint image when resize ends.
Thanks to everybody
EDITED:
I tried this:
protected override void WndProc(ref Message m)
{
const int WM_ENTERSIZEMOVE = 0x0231;
const int WM_EXITSIZEMOVE = 0x0232;
switch (m.Msg)
{
case WM_ENTERSIZEMOVE: resizing = true; break;
case WM_EXITSIZEMOVE: resizing = false; break;
}
}
but those messages are never called 🙁
I post an answer after a long investigation.
First of all I want to thank everybody for your contribution, because your suggestions led me to the right way. Thanks to @Hans Passant too, because his solution on this post is an important piece.
THE PROBLEM:
EndResizeevent in innCntCONTRIBUTES:
PreProcessMessageor overridingWndProc(thanks to @Cipi):I tried these solutions, but I don’t receive WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE messages from Windows
MouseDownandOnResizeevents (thanks to @Cipi):It could be ok, but that logic should be moved on outCnt because innCnt could not receive MouseDown if user is resizing out control or form.
Anyway I don’t like too much this solution
Loadevent of innCnt, hook event handlers to the control’s form’s events (thanks to @hometoast and @pikzen):I tried this solution (and the one provided by @Hans here) but this doesn’t work because when innCnt is loaded, even in if not in
DesignMode, his parent is a part of outCnt, whose parent is null because not ready set!!SOLUTION:
Basicly I had to move @Hans logic inside outCnt but not in
Loadevent, because even here parent is still null!KNOWN PROBLEMS:
I’m quite sure that if outCnt is placed inside another usercontrol, solution provided won’t work…