winforms - Multiple Pages withing one Form? C# -
i haven't done while not quite sure how need, sure pretty simple.
basically, have form navigation pane. want make when user clicks button on pane, 'home' changes content on form, doesn't switch form, if me?
as in, navigation pane stay entire time , want content of form change. 'tabcontrol' tool in visual studio's 'toolbox' although instead of tabs being directly above content, want them buttons displayed in side pane. see image below better understanding. thanks!
(side pane, , header stays same regardless on button pressed, content changes.)

i'd implement using usercontrols. 1 usercontrol shown when button clicked. i'd create interface (for example iview) implemented each usercontrol declares common functionality, example method check whether can switch 1 (like form's onclosing event) this:
public interface iview { bool canclose(); } public usercontrol view1: iview { public bool canclose() { ... } } public usercontrol view2: iview { public bool canclose() { ... } } then, switching views quite easy:
private bool cancurrentviewclose() { if (groupbox1.controls.count == 0) return true; iview v = groupbox1.controls[0] iview; return v.canclose(); } private void switchview(iview newview) { if (groupbox1.controls.count > 0) { usercontrol oldview = groupbox1.controls[0] usercontrol; groupbox1.controls.remove(oldview); oldview.dispose(); } groupbox1.controls.add(newview); newview.dock = dock.fill; } in button this:
private void btnhome_click(object sender, eventargs e) { if (cancurrentviewclose()) { viewhome v = new viewhome(); // further initialization of v here switchview(v); } else { messagebox.show("current view can not close!"); } } i've used approach on many occasions.
Comments
Post a Comment