c# - Why a Panel blinks while removing it and its childs? -
i have form custom controls, usercontrols
. 1 of these controls composed other controls: tablelayoutpanel
, picturebox
(it inside of usercontrol
), label
. visually depicted in following way:
as can see in image, red rectangle usercontrol
, orange rectangles tablelayoutpanel
, yellow , green chairs other usercontrol
controls composed picturebox
, label
.
the chairs (yellow , green ones) draw dynamically. example draw yellow chairs:
private void dibujarsillaseconomicas() { silla[] cheapchairs = m_avion.getcheapchairs(); silla silla; byte fila_silla = 0; byte col_silla = 0; controlvisualchair ctlsillagrafica; for(int num_silla = 0; num_silla < cheapchairs.length; ++num_silla) { silla = cheapchairs[num_silla]; ctlsillagrafica = new controlsillagrafica(silla); ctlsillagrafica.dock = dockstyle.fill; ctlsillagrafica.backcolor = color.black; if (num_silla > 0 & num_silla % 6 == 0) { ++fila_silla; col_silla = 0; } tplsillaseconomicas.controls.add(ctlsillagrafica, col_silla == 3? ++col_silla : col_silla, fila_silla); ++col_silla; } }
these chairs , yellow ones drawn correctly. problem appears when want register passenger:
note when add passenger controls blink. in code when finish adding passenger:
this.controls.remove(ctlavion); // removes actual usercontrol (red rectangle) ctlavion = new controlavion(m_avion); // creates new 1 ctlavion.location = new point(2, 13); ctlavion.size = new size(597, 475); this.controls.add(ctlavion); // adds new usercontrol main controls (a form).
how can avoid blink effect when?
i have tried following usercontrols methods:
ctlavion.invalidate(); ctlavion.update(); ctlavion.refresh();
but not work!
thanks in advance help!
edit:
the answer given @idle_mind specific problem , solved problem re-painting/drawing custom controls have designed.
turn off updates wm_setredraw, update ui, turn them on , refresh form:
// ... @ form level ... private const int wm_setredraw = 11; [system.runtime.interopservices.dllimport("user32.dll")] public static extern int sendmessage(intptr hwnd, int32 wmsg, bool wparam, int32 lparam); // ... method ... sendmessage(this.handle, wm_setredraw, false, 0); // turn updates off this.controls.remove(ctlavion); // removes actual usercontrol (red rectangle) ctlavion = new controlavion(m_avion); // creates new 1 ctlavion.location = new point(2, 13); ctlavion.size = new size(597, 475); this.controls.add(ctlavion); // adds new usercontrol main controls (a form). sendmessage(this.handle, wm_setredraw, true, 0); // turn updates on this.invalidate(); this.refresh();
Comments
Post a Comment