示例#1
0
        private void tabCtrl_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                #region Fecha Aba pelo X
                //Looping through the controls.
                for (int i = 0; i < this.tabCtrl.TabPages.Count; i++)
                {
                    Rectangle r = this.tabCtrl.GetTabRect(i);
                    //Getting the position of the "x" mark.
                    Rectangle closeButton = new Rectangle(r.Right - 15, r.Top + 4, 9, 7);
                    if (closeButton.Contains(e.Location))
                    {
                        if (MessageBox.Show("Tem certeza que deseja fechar esta janela?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            if (this.tabCtrl.TabPages[i].Controls.Count > 0 && this.tabCtrl.TabPages[i].Controls[0] is ctlBase)
                            {
                                ctlBase ctrl = this.tabCtrl.TabPages[i].Controls[0] as ctlBase;
                                if (!ctrl.Fecha())
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
                #endregion

                #region Trata Seleção da Aba
                TabPage objTabPage = this.tabCtrl.TabPages[tabCtrl.SelectedIndex];
                if (objTabPage.Controls.Count > 0 && objTabPage.Controls[0] is ctlBase)
                {
                    ctlBase ctlSelecionado = objTabPage.Controls[0] as ctlBase;
                    ctlSelecionado.SelecionaAba();
                }
                #endregion
            }
            catch (Exception exc)
            {
                controlLog.Insere(Biblioteca.Modelo.Log.LogTipo.Erro, "Erro na execução do evento (tabCtrl1_MouseDown.winInicial)", exc);
            }
        }
示例#2
0
        private void mniRotina_Click(object sender, EventArgs e)
        {
            try
            {
                ToolStripMenuItem objMenuItem = (ToolStripMenuItem)sender;
                if (!tabCtrl.TabPages.ContainsKey(objMenuItem.Text))
                {
                    Assembly currAssembly = Assembly.GetExecutingAssembly();
                    string   ctl          = currAssembly.GetName().Name + "." + ctlTelas[objMenuItem.Text];

                    // Carrega a tela selecionada via reflection
                    ctlBase ctrlCarregado = currAssembly.CreateInstance(ctl) as ctlBase;

                    // Proteção para tela não carregada
                    if (ctrlCarregado.IsDisposed)
                    {
                        return;
                    }

                    tabCtrl.TabPages.Add(objMenuItem.Text, objMenuItem.Text + "           ");
                    TabPage objTabPage = tabCtrl.TabPages[objMenuItem.Text];
                    tabCtrl.SelectTab(objTabPage);

                    this.tabCtrl.Visible = true;
                    objTabPage.Controls.Add(ctrlCarregado);
                    this.ActiveControl = ctrlCarregado;
                    this.ActiveControl.Focus();

                    // Aciona evento para fechar a aba quando fechar uma tela for fechada
                    ctrlCarregado.Disposed += new EventHandler(CloseTab);
                }
            }
            catch (Exception exc)
            {
                controlLog.Insere(Biblioteca.Modelo.Log.LogTipo.Erro, "Erro ao abrir nova tela (mniRotina_Click.winInicial)", exc);
            }
        }