Ejemplo n.º 1
0
        public static ToolStripConfig FromPanel(ToolStrip ts)
        {
            try
            {
                var s= new ToolStripConfig
                        {
                            Name = ts.Name,
                            Visible = ts.Visible,
                            DockStyle = ts.Dock,
                            Location = ts.Location,
                            Left = ts.Left,
                            Top = ts.Top
                        };
                if (ts.Parent != null)
                {
                    s.Parent = ts.Parent.Dock.ToString();
                    var parent = (ts.Parent as ToolStripPanel);
                    if (parent==null)
                    {
                        return s;
                    }
                    for (int index = 0; index < parent.Rows.Length; index++)
                    {
                        var row = parent.Rows[index];
                        if (row.Controls.Contains(ts))
                        {
                            s.Row = index;
                            for (int i = 0; i < row.Controls.Count(); i++)
                            {
                                var c = row.Controls[i];
                                if (c == ts)
                                    s.Index = i;
                            }

                        }
                    }
                }
                else
                {
                    s.Parent = "Top";
                }

                return s;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return Deafult;
            }
        }