Example #1
0
        public void ActualizarControl()
        {
            if (FormActions == null)
            {
                PanelPrimario.Controls.Clear();
                return;
            }

            this.SuspendLayout();
            PanelPrimario.SuspendLayout();

            // Primero elimino los botones que ya no están en la lista
            foreach (System.Windows.Forms.Control btn in PanelPrimario.Controls)
            {
                if (btn is Lui.Forms.LinkLabel)
                {
                    if (FormActions.ContainsKey(btn.Name) == false)
                    {
                        // No existe... lo elimino
                        PanelPrimario.Controls.Remove(btn);
                        btn.Dispose();
                    }
                    else if (FormActions[btn.Name].Visibility != Lazaro.Pres.Forms.FormActionVisibility.Tertiary)
                    {
                        // Existe... pero no en el panel terciario
                        PanelPrimario.Controls.Remove(btn);
                        btn.Dispose();
                    }
                }
            }

            // Ahora agrego o actualizo los botones existentes
            foreach (Lazaro.Pres.Forms.FormAction act in this.FormActions)
            {
                if (act.Visibility == Lazaro.Pres.Forms.FormActionVisibility.Tertiary)
                {
                    if (PanelPrimario.Controls.ContainsKey(act.Name))
                    {
                        // Existe, lo actualizo
                        Lui.Forms.LinkLabel Btn = PanelPrimario.Controls[act.Name] as Lui.Forms.LinkLabel;
                        Btn.Text    = act.Text;
                        Btn.Enabled = act.Enabled;
                    }
                    else
                    {
                        // No existe, lo agrego
                        Lui.Forms.LinkLabel Btn = new Lui.Forms.LinkLabel();
                        Btn.Margin   = new System.Windows.Forms.Padding(4, 0, 0, 0);
                        Btn.Name     = act.Name;
                        Btn.Text     = act.Text;
                        Btn.Enabled  = act.Enabled;
                        Btn.TabIndex = act.TabIndex;
                        Btn.AutoSize = true;
                        //Btn.Size = new System.Drawing.Size(96, PanelPrimario.ClientRectangle.Height);
                        Btn.Visible      = true;
                        Btn.LinkClicked += new LinkLabelLinkClickedEventHandler(this.Btn_LinkClicked);

                        PanelPrimario.Controls.Add(Btn);
                    }
                }
            }

            PanelPrimario.ResumeLayout(true);
            this.ResumeLayout(true);
        }
Example #2
0
        public void ActualizarControl()
        {
            if (FormActions == null)
            {
                PanelPrimario.Controls.Clear();
                PanelSecundario.Controls.Clear();
                return;
            }

            this.SuspendLayout();
            PanelPrimario.SuspendLayout();
            PanelSecundario.SuspendLayout();

            // Primero elimino los botones que ya no están en la lista
            foreach (Control btn in PanelPrimario.Controls)
            {
                if (btn is Lui.Forms.Button)
                {
                    if (FormActions.ContainsKey(btn.Name) == false)
                    {
                        // No existe... lo elimino
                        PanelPrimario.Controls.Remove(btn);
                        btn.Dispose();
                    }
                    else if (FormActions[btn.Name].Visibility != Lazaro.Pres.Forms.FormActionVisibility.Main)
                    {
                        // Existe... pero no en el panel primario
                        PanelPrimario.Controls.Remove(btn);
                        btn.Dispose();
                    }
                }
            }

            foreach (Control btn in PanelSecundario.Controls)
            {
                if (btn is Lui.Forms.Button)
                {
                    if (FormActions.ContainsKey(btn.Name) == false)
                    {
                        // No existe... lo elimino
                        PanelSecundario.Controls.Remove(btn);
                        btn.Dispose();
                    }
                    else if (FormActions[btn.Name].Visibility != Lazaro.Pres.Forms.FormActionVisibility.Secondary)
                    {
                        // Existe... pero no en el panel secundario
                        PanelSecundario.Controls.Remove(btn);
                        btn.Dispose();
                    }
                }
            }

            int PrimaryWidth = 0, SecondaryWidth = 0;

            // Ordeno por TabIndex
            this.FormActions.Sort(delegate(Lazaro.Pres.Forms.FormAction itm, Lazaro.Pres.Forms.FormAction itm2) { return(itm.TabIndex.CompareTo(itm2.TabIndex)); });

            int IdxPri = 0, IdxSec = 0;

            // Ahora agrego o actualizo los botones existentes
            foreach (Lazaro.Pres.Forms.FormAction act in this.FormActions)
            {
                // Me fijo en que panel va
                FlowLayoutPanel Panel;
                if (act.Visibility == Lazaro.Pres.Forms.FormActionVisibility.Main)
                {
                    Panel = this.PanelPrimario;
                }
                else if (act.Visibility == Lazaro.Pres.Forms.FormActionVisibility.Secondary)
                {
                    Panel = this.PanelSecundario;
                }
                else
                {
                    Panel = null;
                }

                if (Panel != null)
                {
                    Lui.Forms.Button Btn;
                    if (Panel.Controls.ContainsKey(act.Name))
                    {
                        // Existe, lo actualizo
                        Btn = Panel.Controls[act.Name] as Lui.Forms.Button;
                    }
                    else
                    {
                        // No existe, lo agrego
                        Btn         = new Lui.Forms.Button();
                        Btn.Margin  = new System.Windows.Forms.Padding(6, 0, 0, 0);
                        Btn.Name    = act.Name;
                        Btn.Size    = new System.Drawing.Size(116, Panel.ClientRectangle.Height);
                        Btn.Visible = true;
                        Btn.Click  += new EventHandler(this.Btn_Click);

                        Panel.Controls.Add(Btn);
                    }

                    Btn.Text    = act.Text;
                    Btn.Subtext = act.SubText;
                    if (act.SubText == null)
                    {
                        Btn.SubLabelPos = SubLabelPositions.None;
                    }
                    else
                    {
                        Btn.SubLabelPos = SubLabelPositions.Bottom;
                    }
                    Btn.Enabled  = act.Enabled;
                    Btn.TabIndex = act.TabIndex;
                    if (Panel == this.PanelPrimario)
                    {
                        Panel.Controls.SetChildIndex(Btn, IdxPri++);
                    }
                    else
                    {
                        Panel.Controls.SetChildIndex(Btn, IdxSec++);
                    }

                    if (act.Visibility == Lazaro.Pres.Forms.FormActionVisibility.Main)
                    {
                        PrimaryWidth += Btn.Width + Btn.Margin.Left + Btn.Margin.Right;
                    }
                    else if (act.Visibility == Lazaro.Pres.Forms.FormActionVisibility.Secondary)
                    {
                        SecondaryWidth += Btn.Width + Btn.Margin.Left + Btn.Margin.Right;
                    }
                }
            }

            PanelPrimario.Width   = PrimaryWidth + 8;
            PanelSecundario.Width = SecondaryWidth + 8;

            PanelSecundario.ResumeLayout(true);
            PanelPrimario.ResumeLayout(true);
            this.ResumeLayout(true);
        }