예제 #1
0
        void AdjustUI()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(AdjustUI));
                return;
            }

            while (tabControlCF1.TabCount > 1)
            {
                tabControlCF1.TabPages.RemoveAt(tabControlCF1.TabCount - 1);
            }

            gbInitParams.Controls.Clear();

            if (null == _dev)
            {
                lbModel.Text        = "空";
                lbID.Text           = "空";
                lbOpend.Text        = "空";
                btOpenClose.Enabled = false;
                btOpenClose.Text    = "空设备";
                return;
            }
            else //更新设备信息
            {
                lbModel.Text = _dev.DeviceModel;
                lbID.Text    = _id;
                //UpdateDevice();

                int   locY      = 20;
                int   locX      = 5;
                Label lbDevInit = new Label();
                lbDevInit.Text     = _dev.IsInitOK?"初始化完成":"初始化失败";
                lbDevInit.Location = new Point(locX, locY);
                gbInitParams.Controls.Add(lbDevInit);
                locY += 28;
                for (int i = 0; i < _dev.InitParamNames.Length; i++)
                {
                    UcJFParamEdit ucParam = new UcJFParamEdit();
                    ucParam.SetParamDesribe(_dev.GetInitParamDescribe(_dev.InitParamNames[i]));
                    ucParam.SetParamValue(_dev.GetInitParamValue(_dev.InitParamNames[i]));
                    ucParam.Enabled  = false;
                    ucParam.Location = new Point(locX, locY);
                    gbInitParams.Controls.Add(ucParam);
                    ucParam.Width = gbInitParams.Width - 20;
                    locY          = ucParam.Bottom + 2;
                }

                if (_dev.DioCount > 0)
                {
                    ///fmDios = new FormDios();
                    for (int i = 0; i < _dev.DioCount; i++)
                    {
                        fmDios.AddModule(_dev.GetDio(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "DIO模块";
                    tabPage.Name      = "DioModules";
                    tabPage.BackColor = fmDios.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmDios.TopLevel        = false;
                    fmDios.FormBorderStyle = FormBorderStyle.None;
                    fmDios.Dock            = DockStyle.Fill;
                    fmDios.Parent          = tabPage;
                    fmDios.Visible         = true;
                    tabPage.Controls.Add(fmDios);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.McCount > 0)
                {
                    //fmMotions = new FormMotions();
                    for (int i = 0; i < _dev.McCount; i++)
                    {
                        fmMotions.AddModule(_dev.GetMc(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "Motion模块";
                    tabPage.Name      = "MotionModules";
                    tabPage.BackColor = fmMotions.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmMotions.TopLevel        = false;
                    fmMotions.FormBorderStyle = FormBorderStyle.None;
                    fmMotions.Dock            = DockStyle.Fill;
                    fmMotions.Parent          = tabPage;
                    fmMotions.Visible         = true;
                    tabPage.Controls.Add(fmMotions);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.CompareTriggerCount > 0)
                {
                    for (int i = 0; i < _dev.CompareTriggerCount; i++)
                    {
                        fmCmprTrigs.AddModule(_dev.GetCompareTrigger(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "CmprTrig模块";
                    tabPage.Name      = "CmprTrigModule";
                    tabPage.BackColor = fmCmprTrigs.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmCmprTrigs.TopLevel        = false;
                    fmCmprTrigs.FormBorderStyle = FormBorderStyle.None;
                    fmCmprTrigs.Dock            = DockStyle.Fill;
                    fmCmprTrigs.Parent          = tabPage;
                    fmCmprTrigs.Visible         = true;
                    tabPage.Controls.Add(fmCmprTrigs);  //tabPage选项卡添加一个窗体对象
                }

                if (_dev.AioCount > 0)
                {
                    for (int i = 0; i < _dev.AioCount; i++)
                    {
                        fmAios.AddModule(_dev.GetAio(i), "模块_" + i.ToString());
                    }

                    TabPage tabPage = new TabPage(); //创建一个TabControl 中的单个选项卡页。
                    tabPage.Text      = "AIO模块";
                    tabPage.Name      = "AioModules";
                    tabPage.BackColor = fmAios.BackColor;

                    tabControlCF1.TabPages.Add(tabPage);   //添加tabPage选项卡到tab控件

                    fmAios.TopLevel        = false;
                    fmAios.FormBorderStyle = FormBorderStyle.None;
                    fmAios.Dock            = DockStyle.Fill;
                    fmAios.Parent          = tabPage;
                    fmAios.Visible         = true;
                    tabPage.Controls.Add(fmAios);  //tabPage选项卡添加一个窗体对象
                }
            }

            tabControlCF1.SelectedIndex = 0;
            UpdateModuleStatus();
        }