VB.NET - How to add borders on an MDI child borderless form? -
i using way below, add borders mdi child borderless forms...
private sub form_paint(sender object, e system.windows.forms.painteventargs) handles me.paint if me.windowstate = formwindowstate.maximized me.padding = new padding(0, 0, 0, 0) me.backcolor = color.fromargb(76, 76, 76) else dim mf_rect new rectangle(5, 5, me.clientsize.width, me.clientsize.height) dim mf_color = new solidbrush(color.fromargb(76, 76, 76)) e.graphics.fillrectangle(mf_color, mf_rect) me.padding = new padding(5, 5, 5, 5) me.backcolor = color.fromargb(64, 64, 64) end if end sub
but, if mdi child form steps out of mdi parent's borders, half of it, , maximize , normalize again, borders gone!!! if slide in, see them again!!!
any idea why happening?
the dragging of form outside of mdi parent's borders not required reproduce behavior. need maximize , normalize form.
the problem form not being repainted after has been resized. default behavior, , makes degree of sense—the portion of client area visible has always been visible, , therefore still (presumably) painted correctly. optimization, then, no repaint performed.
but behavior doesn't work you, because painting logic tied current size of form. if form changes size, want repaint can calculate new painting dimensions.
you can hack forcing invalidation (and therefore repaint) of client area in response resize event. invalidate
member function this.
but there better solution causes happen automatically. set form's resizeredraw
property true
. can either designer (in properties window) or in form class constructor. (note equivalent calling setstyle
member function , specifying controlstyles.resizeredraw
flag.)
an better approach separate painting of borders (which logically in non-client area) painting of contents of form (which logical client area). won't go how in answer, can find discussion , various tutorials elsewhere online. example, drawing custom borders in windows forms. article part of larger library implements effect you. not sure how/if library work mdi children. mdi effect has been deprecated many years…
Comments
Post a Comment