.net - How to stop C# form from rendering the controls -
i using bufferedgraphics
redraw form. wish redraw form's controls myself, can draw lines wherever want while can still use form designer align controls.
i've tried suspendlayout
make no use here.
code:
using system; using system.drawing; using system.windows.forms; public partial class form1 : form { bufferedgraphicscontext context; bufferedgraphics grafx; picturebox pic1, pic2; public form1() { setstyle((controlstyles)(controlstyles.allpaintinginwmpaint | controlstyles.userpaint), true); initializecomponent(); //add picturebox pic1 = new picturebox(); pic1.backcolor = color.black; pic1.setbounds(50, 50, 100, 50); controls.add(pic1); pic2 = new picturebox(); pic2.backcolor = color.gray; pic2.setbounds(75, 50, 50, 100); controls.add(pic2); } private void form1_load(object sender, eventargs e) { context = bufferedgraphicsmanager.current; context.maximumbuffer = new size(width, height); grafx = context.allocate(creategraphics(), new rectangle(0, 0, width, height)); } public override void refresh() { } protected override void onpaintbackground(painteventargs e) { } protected override void onpaint(painteventargs e) { graphics g = grafx.graphics; g.clear(backcolor); bitmap bmp = new bitmap(width, height); foreach (control c in controls) c.drawtobitmap(bmp, new rectangle(c.left, c.top, c.width, c.height)); g.drawimage(bmp, 0, 0); g.drawline(new pen(color.red, 4), 0, 0, clientsize.width, clientsize.height); grafx.render(graphics.fromhwnd(handle)); } private void form1_resize(object sender, eventargs e) { context.maximumbuffer = new size(this.width, this.height); if (grafx != null) { grafx.dispose(); grafx = null; } grafx = context.allocate(this.creategraphics(), new rectangle(0, 0, width, height)); base.refresh(); } }
i need line drawn @ top of controls (picturebox), code turns out drawn below controls.
Comments
Post a Comment