CycleHYControl.cs 2.0 KB
using DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TheMachine
{
    public partial class CycleHYControl<T1> : UserControl where T1: UserControl, Idevicetab,new()
    {
        public CycleHYControl()
        {
            InitializeComponent();
        }
        List<T1> hYControls = new List<T1>();
        public string DeviceName = "";
        public void Init(string devicegroup) {
            tabControl1.TabPages.Clear();
            foreach (var dg in RobotManage.DeviceGroup.Values) {
                if (dg.DeviceType != devicegroup)
                    continue;

                if (string.IsNullOrEmpty(DeviceName))
                    DeviceName = dg.Name;

                var hy = new T1();
                hy.Init(dg.GroupName);
                hYControls.Add(hy);
                AddForm(dg.GroupName, dg.GroupName, hy);
            }
        }

        private void AddForm(string id, string text, UserControl form)
        {
            foreach (TabPage tp in tabControl1.TabPages)
            {
                if (tp.Name == id)
                {
                    tp.Text = text;
                    return;
                }
            }

            TabPage lineTabPage = new TabPage(text);
            lineTabPage.Name = id;
            Panel linePan = new Panel();
            linePan.Dock = DockStyle.Fill;
            linePan.AutoScroll = true;
            lineTabPage.Controls.Add(linePan);
            linePan.Controls.Add(form);
            form.Dock = DockStyle.Fill;
            linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
            form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
            form.Show();
            tabControl1.TabPages.Add(lineTabPage);
        }
    }
}