I am trying to build a user control that has serveral pages, similar to a TabControl control. Below are some fragments of the control. For short I'll call it UC.
UC contains two panels. One is of no interest in this context, the other is called 'pan__panels' (actually a class derived from Panel) which accepts controls the user can drag to it. The user can add tabs to the control (which is not visible in the code below). For each tab he adds the method 'AddNewPanel' is invoked, i.e. the tab is associated with a panel. The tabs are owner drawn vertically or horizontally according to the text and image the user defines.
The panels linked to a tab are never visible. The only visible panel is pan__panels. If the user clicks a tab, all contols on 'pan__panels' are moved to the currently active panel, the panel associated to the clicked tab becomes the active one and its controls are moved to 'pan__panels'.
I create a TestForm, drag a UC control to it, add some tabs to it and on each page a control or two. This works quite fine so far. But the big problem is, that the whole stuff is not persistent (and thus of no use).
Even if I add the new panels to UC.Controls, they are not serialized. The controls I added, are all added to TestForm.Designer and so are the tabs. But how do I get the panels and the links between the controls and the panels to TestForm.Designer?
Though I have used days going through much of the stuff on the internet about serialization, I have not come accrosss anything that would help me any further.
I have also tried a totally different concept, adding a specific object to the Tag property of controls (not placing them an separate panels). But then the very same problem arises: how do I serialize the object assigned to Tag?
Maybe there's an altogether better approach to the whole thing. Any suggestions are welcome. And thanks for any hint anyway.
Walter
| 1 | //thisisthecontroltheusercandragfromthetoolboxtoaformorpanelorwhatever
| | 2 |
| | 3 | usingSystem;
| | 4 | usingSystem.Collections.Generic;
| | 5 | usingSystem.ComponentModel;
| | 6 | usingSystem.Drawing;
| | 7 | usingSystem.Data;
| | 8 | usingSystem.Text;
| | 9 | usingSystem.Windows.Forms;
| | 10 |
| | 11 | namespaceOwnComponents.NormTabs
| | 12 | {
| | 13 |
| | 14 | //thisdesignerclassmakesthepanel'pan__panels'(placedonthisform)capableof
| | 15 | //receivingcontrolsfromthetoolbox(bydraganddrop)
| | 16 | [Designer(typeof(cmpNormTabsDesigner))]
| | 17 | publicpartialclasscmpNormTabs:UserControl
| | 18 | {
| | 19 | | | 20 | | | 21 | privatePanelfRecentTab;
| | 22 | privateTTabPosfTabAlign;
| | 23 |
| | 24 | privateList<Panel>fPanels;
| | 25 |
| | 26 | publicTTabPosTabAlign{get{returnfTabAlign;}set{HandleAlign(value);}}
// this actually does not belong to this class, just for info. The user can edit it in the designer, causing "AddTab" to be invoked. | | 27 |
// public TTabHelp [] Tabs { get { return fTabs; } set { HandleTabNames ( value ); } }
| | 28 | //thiscrashesthevisualstudio
| | 29 | //[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
| | 30 | //publicList<Panel>Panels{get{returnfPanels;}set{fPanels=value;}}
| | 31 |
| | 32 |
| | 33 | publiccmpNormTabs()
| | 34 | {
| | 35 | InitializeComponent();
| | 36 |
| | 37 | fPanels=newList<Panel>();
| | 38 | fTabAlign=TTabPos.cTpBtm;
| | 39 | HandleAlign(TTabPos.cTpLeftV);//Default
| | 40 | }
| | 41 |
| | 42 | publicTNormTabsPanelTabPanel{get{returnpan__tabs;}}
| | 43 |
| | 44 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
| | 45 | publicTNormTabsPanelControlPanel{get{returnpan__panels;}}
| | 46 |
| | 47 | //calledwhentheuserchangestheTabAlignproperty
| | 48 | privatevoidHandleAlign(TTabPosaAlign)
| | 49 | {
| | 50 | //somecode
| | 51 | }
| | 52 |
| | 53 | //calledwhenclickingonatab(atdesigntime,fromanotherclass)
| | 54 | internalvoidHandleTab(PanelaPan)
| | 55 | {
| | 56 | if(fRecentTab==aPan)
| | 57 | {return;}
| | 58 |
| | 59 | PanelxPanS=aPan;
| | 60 | PanelxPanD=fRecentTab;
| | 61 |
| | 62 | while(pan__panels.Controls.Count>0)
| | 63 | {
| | 64 | xPanD.Controls.Add(pan__panels.Controls[0]);
| | 65 | }
| | 66 |
| | 67 | while(xPanS.Controls.Count>0)
| | 68 | {
| | 69 | pan__panels.Controls.Add(xPanS.Controls[0]);
| | 70 | }
| | 71 | fRecentTab=aPan;
| | 72 | }
| | 73 |
| | 74 |
| | 75 | //calledwhentheuser(atdesigntime)changesthetabs
| | 76 | internalPanelAddNewPanel()
| | 77 | {
| | 78 | PanelxPan=newPanel();
| | 79 |
| | 80 | xPan.Name="panel"+(fPanels.Count+1).ToString();
| | 81 | xPan.Location=newPoint(0,0);
| | 82 | xPan.Size=newSize(100,100);
| | 83 | xPan.Visible=false;
| | 84 |
| | 85 | fPanels.Add(xPan);
| | 86 |
| | 87 | //doesn'tdoanyharmbutalsoisofnouse
| | 88 | this.Controls.Add(xPan);
| | 89 |
| | 90 | if(fRecentTab==null)
| | 91 | {fRecentTab=fPanels[0];}
| | 92 |
| | 93 | returnxPan;
| | 94 | }
| | 95 | }
| | 96 | }
| | 97 |
| | 98 | |
|
|
|
|