How to create an options form in C# Windows Forms? -


http://i.stack.imgur.com/v58ov.png

see picture above. screenshot visual studio's options form.

the left side treeview. right side various controls change program options. when nodes in treeview selected, right side changes, showing different options.

how program this? right side have 50 overlapping panels, , selecting of nodes changes panel visible? if case, how go managing such? mess in designer.

no don't make 50 overlapping panels. create several usercontrols and, example, link types on tag of node. can use activator create controls. create 1 treeview , 1 panel: (pseudo code)

// create nodes: treenode item = new treenode();  item.tag = typeof(usercontrol1);  treeview.nodes.add( item );   // field currentcontrol usercontrol _currentcontrol;   // on selection: treeviewitem item = (treeviewitem)sender;  if(_currentcontrol != null) {    _currentcontrol.controls.remove(_currentcontrol);    _currentcontrol.dispose(); }  // if no type bound node, leave panel empty if (item.tag == null)   return;  _currentcontrol = (usercontrol)activator.create((type)item.tag); panel1.controls.add(_currentcontrol); 

the next question be, "i'd call save method, or requestclose method in controls". this, should implement interface on controls, , when switch nodes, try cast _currentusercontrol irequestclose interface , call, example, bool requestclose(); method.

 // on selection:  treeviewitem item = (treeviewitem)sender;   if(_currentcontrol != null)  {     // if _currentcontrol supports irequestclose interface:     if(_currentcontrol irequestclose)         // cast _currentcontrol irequestcode , call requestclose method.         if(!((irequestclose)_currentcontrol).requestclose())              // usercontrol decides whether control closed/disposed or not.              return;      _currentcontrol.controls.remove(_currentcontrol);     _currentcontrol.dispose();  }   if (item.tag == null)    return;  _currentcontrol = (usercontrol)activator.create(item.tag); panel1.controls.add(_currentcontrol); 

but next step.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -