.net - Add button control(s) to SplitContainer Splitter -
is there way display controls (like buttons) on adjustable splitter displays between 2 panels in .net splitcontainer
?
example:
i don't think splitcontainer
natively supports this, overriding control functionality seems omni-present in numerous applications seems bit me - feel i'm over-thinking or missing obvious.
here's example uses tablelayoutpanel simulate splitcontainer.
using system; using system.diagnostics; using system.drawing; using system.windows.forms; class form1 : form { [stathread] static void main() { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new form1()); } tablelayoutpanel rootpanel; float originalwidth; int splitpointx; public form1() { controls.add(rootpanel = new tablelayoutpanel { columncount = 3, columnstyles = { // notice use of absolute here control 'splitting' new columnstyle(sizetype.absolute, 120f), // size of button panel new columnstyle(sizetype.autosize), // remaining size new columnstyle(sizetype.percent, 100f), }, dock = dockstyle.fill, rowcount = 1, rowstyles = { new rowstyle(sizetype.percent, 100f) }, }); panel buttonpanel; rootpanel.controls.add(buttonpanel = new panel { anchor = anchorstyles.top | anchorstyles.bottom, backcolor = systemcolors.controldark, margin = new padding(0), minimumsize = new size(80, 0), size = new size(80, 0), controls = { // usevisualstylebackcolor = true because altered container's backcolor new button { text = ">>", location = new point(19, 112), size = new size(40, 23), usevisualstylebackcolor = true }, new button { text = ">", location = new point(19, 83), size = new size(40, 23), usevisualstylebackcolor = true }, new button { text = "<", location = new point(19, 54), size = new size(40, 23), usevisualstylebackcolor = true }, new button { text = "<<", location = new point(19, 25), size = new size(40, 23), usevisualstylebackcolor = true }, }, }, 1, 0); buttonpanel.mousedown += (s, e) => { if (e.button == mousebuttons.left) { // capture mouse mouse move messages go control (s control).capture = true; // record original column width originalwidth = rootpanel.columnstyles[0].width; // record first clicked point // convert screen coordinates because window moving target point windowpoint = (s control).pointtoscreen(e.location); splitpointx = windowpoint.x; } }; buttonpanel.mousemove += (s, e) => { if ((s control).capture) { point windowpoint = (s control).pointtoscreen(e.location); // calculate distance of mouse splitpoint int offset = windowpoint.x - splitpointx; // apply originalwidth float newwidth = originalwidth + offset; // clamp it. // control in left pane's minimumsize.width more appropriate 0 newwidth = math.max(0, newwidth); // update column width if (math.abs(newwidth - rootpanel.columnstyles[0].width) >= 1) rootpanel.columnstyles[0].width = newwidth; } }; buttonpanel.mouseup += (s, e) => { if (e.button == mousebuttons.left) { // release mouse capture if ((s control).capture) (s control).capture = false; } }; } }
Comments
Post a Comment