コード例 #1
0
ファイル: TabbedGroups.cs プロジェクト: nithinphilips/SMOz
 public virtual void OnPageLoading(TGPageLoadingEventArgs e)
 {
     // Has anyone registered for the event?
     if (PageLoading != null)
         PageLoading(this, e);
 }
コード例 #2
0
        public override void LoadFromXml(XmlTextReader xmlIn)
        {
            // Grab the expected attributes
            string rawCount  = xmlIn.GetAttribute(0);
            string rawUnique = xmlIn.GetAttribute(1);
            string rawSpace  = xmlIn.GetAttribute(2);

            // Convert to correct types
            int     count  = Convert.ToInt32(rawCount);
            int     unique = Convert.ToInt32(rawUnique);
            Decimal space  = Convert.ToDecimal(rawSpace);

            // Update myself with new values
            _unique = unique;
            _space  = space;

            // Load each of the children
            for (int i = 0; i < count; i++)
            {
                // Read to the first page element or
                if (!xmlIn.Read())
                {
                    throw new ArgumentException("An element was expected but could not be read in");
                }

                // Must always be a page instance
                if (xmlIn.Name == "Page")
                {
                    Controls.TabPage tp = new Controls.TabPage();

                    // Grab the expected attributes
                    string title         = xmlIn.GetAttribute(0);
                    string rawImageList  = xmlIn.GetAttribute(1);
                    string rawImageIndex = xmlIn.GetAttribute(2);
                    string rawSelected   = xmlIn.GetAttribute(3);
                    string controlType   = xmlIn.GetAttribute(4);

                    // Convert to correct types
                    bool imageList  = Convert.ToBoolean(rawImageList);
                    int  imageIndex = Convert.ToInt32(rawImageIndex);
                    bool selected   = Convert.ToBoolean(rawSelected);

                    // Setup new page instance
                    tp.Title      = title;
                    tp.ImageIndex = imageIndex;
                    tp.Selected   = selected;

                    if (imageList)
                    {
                        tp.ImageList = _tabbedGroups.ImageList;
                    }

                    // Is there a type description of required control?
                    if (controlType != "null")
                    {
                        try
                        {
                            // Get type description, if possible
                            Type t = Type.GetType(controlType);

                            // Was a valid, known type?
                            if (t != null)
                            {
                                // Get the assembly this type is defined inside
                                Assembly a = t.Assembly;

                                if (a != null)
                                {
                                    // Create a new instance form the assemnly
                                    object newObj = a.CreateInstance(t.FullName);

                                    Control newControl = newObj as Control;

                                    // Must derive from Control to be of use to us
                                    if (newControl != null)
                                    {
                                        tp.Control = newControl;
                                    }
                                }
                            }
                        }
                        catch
                        {
                            // We ignore failure to recreate given control type
                        }
                    }

                    // Read to the custom data element
                    if (!xmlIn.Read())
                    {
                        throw new ArgumentException("An element was expected but could not be read in");
                    }

                    if (xmlIn.Name != "CustomPageData")
                    {
                        throw new ArgumentException("Expected 'CustomPageData' element was not found");
                    }

                    bool finished = xmlIn.IsEmptyElement;

                    TGPageLoadingEventArgs e = new TGPageLoadingEventArgs(tp, xmlIn);

                    // Give handlers chance to reconstruct per-page information
                    _tabbedGroups.OnPageLoading(e);

                    // Add into the control unless handler cancelled add operation
                    if (!e.Cancel)
                    {
                        _tabControl.TabPages.Add(tp);
                    }

                    // Read everything until we get the end of custom data marker
                    while (!finished)
                    {
                        // Check it has the expected name
                        if (xmlIn.NodeType == XmlNodeType.EndElement)
                        {
                            finished = (xmlIn.Name == "CustomPageData");
                        }

                        if (!finished)
                        {
                            if (!xmlIn.Read())
                            {
                                throw new ArgumentException("An element was expected but could not be read in");
                            }
                        }
                    }

                    // Read past the end of page element
                    if (!xmlIn.Read())
                    {
                        throw new ArgumentException("An element was expected but could not be read in");
                    }

                    // Check it has the expected name
                    if (xmlIn.NodeType != XmlNodeType.EndElement)
                    {
                        throw new ArgumentException("End of 'page' element expected but missing");
                    }
                }
                else
                {
                    throw new ArgumentException("Unknown element was encountered");
                }
            }
        }
コード例 #3
0
		public virtual void OnPageLoading(TGPageLoadingEventArgs e) {
			// Has anyone registered for the event?
			if (PageLoading != null)
				PageLoading(this, e);
		}
コード例 #4
0
        public override void LoadFromXml(XmlTextReader xmlIn)
        {
            // Grab the expected attributes
            string rawCount = xmlIn.GetAttribute(0);
            string rawUnique = xmlIn.GetAttribute(1);
            string rawSpace = xmlIn.GetAttribute(2);

            // Convert to correct types
            int count = Convert.ToInt32(rawCount);
            int unique = Convert.ToInt32(rawUnique);
            Decimal space = Convert.ToDecimal(rawSpace);

            // Update myself with new values
            _unique = unique;
            _space = space;

            // Load each of the children
            for(int i=0; i<count; i++)
            {
                // Read to the first page element or
                if (!xmlIn.Read())
                    throw new ArgumentException("An element was expected but could not be read in");

                // Must always be a page instance
                if (xmlIn.Name == "Page")
                {
                    Controls.TabPage tp = new Controls.TabPage();

                    // Grab the expected attributes
                    string title = xmlIn.GetAttribute(0);
                    string rawImageList = xmlIn.GetAttribute(1);
                    string rawImageIndex = xmlIn.GetAttribute(2);
                    string rawSelected = xmlIn.GetAttribute(3);
                    string controlType = xmlIn.GetAttribute(4);

                    // Convert to correct types
                    bool imageList = Convert.ToBoolean(rawImageList);
                    int imageIndex = Convert.ToInt32(rawImageIndex);
                    bool selected = Convert.ToBoolean(rawSelected);

                    // Setup new page instance
                    tp.Title = title;
                    tp.ImageIndex = imageIndex;
                    tp.Selected = selected;

                    if (imageList)
                        tp.ImageList = _tabbedGroups.ImageList;

                    // Is there a type description of required control?
                    if (controlType != "null")
                    {
                        try
                        {
                            // Get type description, if possible
                            Type t = Type.GetType(controlType);

                            // Was a valid, known type?
                            if (t != null)
                            {
                                // Get the assembly this type is defined inside
                                Assembly a = t.Assembly;

                                if (a != null)
                                {
                                    // Create a new instance form the assemnly
                                    object newObj = a.CreateInstance(t.FullName);

                                    Control newControl = newObj as Control;

                                    // Must derive from Control to be of use to us
                                    if (newControl != null)
                                        tp.Control = newControl;
                                }
                            }
                        }
                        catch
                        {
                            // We ignore failure to recreate given control type
                        }
                    }

                    // Read to the custom data element
                    if (!xmlIn.Read())
                        throw new ArgumentException("An element was expected but could not be read in");

                    if (xmlIn.Name != "CustomPageData")
                        throw new ArgumentException("Expected 'CustomPageData' element was not found");

                    bool finished = xmlIn.IsEmptyElement;

                    TGPageLoadingEventArgs e = new TGPageLoadingEventArgs(tp, xmlIn);

                    // Give handlers chance to reconstruct per-page information
                    _tabbedGroups.OnPageLoading(e);

                    // Add into the control unless handler cancelled add operation
                    if (!e.Cancel)
                        _tabControl.TabPages.Add(tp);

                    // Read everything until we get the end of custom data marker
                    while(!finished)
                    {
                        // Check it has the expected name
                        if (xmlIn.NodeType == XmlNodeType.EndElement)
                            finished = (xmlIn.Name == "CustomPageData");

                        if (!finished)
                        {
                            if (!xmlIn.Read())
                                throw new ArgumentException("An element was expected but could not be read in");
                        }
                    }

                    // Read past the end of page element
                    if (!xmlIn.Read())
                        throw new ArgumentException("An element was expected but could not be read in");

                    // Check it has the expected name
                    if (xmlIn.NodeType != XmlNodeType.EndElement)
                        throw new ArgumentException("End of 'page' element expected but missing");

                }
                else
                    throw new ArgumentException("Unknown element was encountered");
            }
        }
コード例 #5
0
 private void PageLoading(Crownwood.Magic.Controls.TabbedGroups tg, Crownwood.Magic.Controls.TGPageLoadingEventArgs e)
 {
     // Read back the text box contents
     (e.TabPage.Control as RichTextBox).Text = e.XmlIn.ReadString();
 }