예제 #1
0
        public void Bind(TabControl tctrl, CtlWizardOptions opts)
        {
            tctrl.FindForm().AcceptButton = _btnNext;
            tctrl.FindForm().CancelButton = _btnBack;
            _btnBack.DialogResult = DialogResult.None; // Annoyingly CancelButton sets this

            this.Pager              = new PagerControl(ref tctrl, this.panel1);
            this.Pager.PageChanged += this.pc_PageChanged;
            this.pc_PageChanged(this.Pager, EventArgs.Empty);
            this.Options = opts;
        }
        /// <summary>
        /// 将标签转化为窗体
        /// </summary>
        /// <param name="tab">标签容器</param>
        /// <param name="index">索引</param>
        /// <param name="isRestore">关闭窗体是否还原标签</param>
        public static void PageToForm(TabControl tab, int index, bool isRestore)
        {
            if (tab == null)
            {
                return;
            }
            TabPage page = tab.TabPages[index];
            Dictionary <string, object> tagDuc = new Dictionary <string, object>();

            Control[] conArr = new Control[page.Controls.Count];
            Form      form   = new Form();

            form.Show();
            form.Name     = DateTime.Now.Ticks.ToString() + "_Form";
            form.Size     = page.Size;
            form.Icon     = tab.FindForm().Icon;
            form.Location = tab.FindForm().Location;
            form.Text     = tab.FindForm().Text + "_" + page.Text;
            tagDuc.Add("page", page);
            tagDuc.Add("index", index);
            form.Tag = tagDuc;
            // 窗口关闭后还原到tab容器中
            if (isRestore)
            {
                form.FormClosing += (object sender, FormClosingEventArgs e) => {
                    object objTag = form.Tag;
                    if (objTag != null && objTag is Dictionary <string, object> )
                    {
                        Dictionary <string, object> dic = (Dictionary <string, object>)objTag;
                        TabPage pp = (TabPage)dic["page"];
                        int     i  = (int)dic["index"];
                        form.Controls.CopyTo(conArr, 0);
                        pp.Controls.AddRange(conArr);
                        tab.TabPages.Insert(i, pp);
                    }
                };
            }
            page.Controls.CopyTo(conArr, 0);
            form.Controls.AddRange(conArr);
            tab.TabPages.Remove(page);
            form.Activate();
        }
 private void btnClose_Click(object sender, EventArgs e)
 {
     if ((this.Parent != null) && (this.Parent is TabPage))
     {
         TabPage                tpage    = (TabPage)this.Parent;
         TabControl             tcontrol = (TabControl)tpage.Parent;
         EasyETLDemoApplication app      = ((EasyETLDemoApplication)(tcontrol.FindForm()));
         tcontrol.TabPages.Remove(tpage);
         app.FocusClientsTreeView();
     }
 }
 /// <summary>
 /// 将控件添加到Tab容器中
 /// </summary>
 /// <param name="con">控件</param>
 /// <param name="isSynSize">是否同步大小</param>
 /// <param name="isAnchor">是否锚定</param>
 public static void AddControlsToPage(TabControl tab, TabPage page, Control con, bool isSynSize, bool isAnchor)
 {
     // 获得Page
     page.Controls.Add(con);
     tab.TabPages.Add(page);
     tab.SelectedTab = page;
     tab.FindForm().ActiveControl = con;
     if (isSynSize)
     {
         con.Size = new Size(page.ClientSize.Width - con.Location.X, page.ClientSize.Height - con.Location.Y);
     }
     // 设置文本框四周锚定
     if (isAnchor)
     {
         con.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
     }
 }
예제 #5
0
파일: SSTabHelper.cs 프로젝트: xxdoc/SKS
        /// <summary>
        /// Process a UseMnemonic property for a tabControl when this was delayed.
        /// </summary>
        /// <param name="tabControl">The TabControl to process.</param>
        private static void ProcessDelayedUseMnemonic(TabControl tabControl)
        {
            bool value = (bool)newProperties[tabControl.GetHashCode()][newPropertiesEnum.UseMnemonic];

            Form parentForm = tabControl.FindForm();
            int  code       = parentForm.GetHashCode();

            if (value)
            {
                parentForm.KeyPreview = true;
                parentForm.KeyDown   += TabControl_ParentForm_KeyDown;

                if (!FormsWithTabsControlsUsingMnemonic.ContainsKey(code))
                {
                    FormsWithTabsControlsUsingMnemonic.Add(code, new List <TabControl>());
                    FormClosedEventHandler handler = new FormClosedEventHandler(delegate(object sender, FormClosedEventArgs e)
                    {
                        FormsWithTabsControlsUsingMnemonic.Remove(code);
                        parentForm.KeyDown -= TabControl_ParentForm_KeyDown;
                    });
                    parentForm.FormClosed += handler;
                }
                FormsWithTabsControlsUsingMnemonic[code].Add(tabControl);
            }
            else
            {
                parentForm.KeyPreview = false;
                parentForm.KeyDown   -= TabControl_ParentForm_KeyDown;

                if (FormsWithTabsControlsUsingMnemonic.ContainsKey(code))
                {
                    if (FormsWithTabsControlsUsingMnemonic[code].Contains(tabControl))
                    {
                        FormsWithTabsControlsUsingMnemonic[code].Remove(tabControl);
                    }

                    if (FormsWithTabsControlsUsingMnemonic[code].Count == 0)
                    {
                        FormsWithTabsControlsUsingMnemonic.Remove(code);
                    }
                }
            }
        }
        /// <summary>
        /// 将窗体数组添加到Tab容器中
        /// </summary>
        /// <param name="forms">窗体数组</param>
        /// <param name="isSynSize">是否同步大小</param>
        /// <param name="isAnchor">是否锚定</param>
        public static void AddControlsToPage(TabControl tab, TabPage page, Form form, bool isSynSize, bool isAnchor)
        {
            tab.TabPages.Add(page);
            Size minSize = form.MinimumSize;

            // 判断是否设置了最小大小
            if (page.FindForm().Size.Width < minSize.Width)
            {
                page.FindForm().Width = minSize.Width;
            }
            if (page.FindForm().Size.Height < minSize.Height)
            {
                page.FindForm().Height = minSize.Height;
            }
            page.Text        = form.Text;
            page.ToolTipText = form.Text;

            if (isSynSize)
            {
                form.ClientSize = new Size(page.Size.Width, page.Size.Height - 2);
            }
            if (isAnchor)
            {
                form.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
            }
            form.FormBorderStyle = FormBorderStyle.None;
            form.AutoScaleMode   = AutoScaleMode.None;
            form.TopLevel        = false;
            form.Parent          = page;
            tab.FindForm().ActiveControl = form;
            tab.SelectedTab = page;

            form.BringToFront();
            form.Show();
            // 设置窗体属性
            form.Location = new Point(0, 2);
        }