private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            object o = e.Item.Tag;

            if (o is DilateConfig)
            {
                DilateConfig config = o as DilateConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is ErodeConfig)
            {
                ErodeConfig config = o as ErodeConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is OpenConfig)
            {
                OpenConfig config = o as OpenConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is CloseConfig)
            {
                CloseConfig config = o as CloseConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is ThresholdConfig)
            {
                ThresholdConfig config = o as ThresholdConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is GainOffsetConfig)
            {
                GainOffsetConfig config = o as GainOffsetConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is RoataeConfig)
            {
                RoataeConfig config = o as RoataeConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is MedianConfig)
            {
                MedianConfig config = o as MedianConfig;
                config.Enable = e.Item.Checked;
            }
            else if (o is SobelConfig)
            {
                SobelConfig config = o as SobelConfig;
                config.Enable = e.Item.Checked;
            }
            //Run();
        }
        protected override void UpdateEventToUI()
        {
            base.UpdateEventToUI();

            foreach (var o in imgEvent.config.CfgGroup)
            {
                ListViewItem item = new ListViewItem();
                if (o is DilateConfig)
                {
                    DilateConfig config = o as DilateConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Width.ToString() + "," + config.Height.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is ErodeConfig)
                {
                    ErodeConfig config = o as ErodeConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Width.ToString() + "," + config.Height.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is OpenConfig)
                {
                    OpenConfig config = o as OpenConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Width.ToString() + "," + config.Height.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is CloseConfig)
                {
                    CloseConfig config = o as CloseConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Width.ToString() + "," + config.Height.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is ThresholdConfig)
                {
                    ThresholdConfig config = o as ThresholdConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    switch (config.Mode)
                    {
                    case ThresholdConfig.MyThresholdMode.Auto:
                        item.SubItems.Add("Auto");
                        break;

                    case ThresholdConfig.MyThresholdMode.Absolute:
                        item.SubItems.Add(config.AbsoluteValue.ToString());
                        break;

                    case ThresholdConfig.MyThresholdMode.Relative:
                        item.SubItems.Add(config.RelativeValue.ToString());
                        break;

                    default:
                        break;
                    }

                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is GainOffsetConfig)
                {
                    GainOffsetConfig config = o as GainOffsetConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Gain.ToString() + "," + config.Offset.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is RoataeConfig)
                {
                    RoataeConfig config = o as RoataeConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.SubItems.Add(config.Value.ToString());
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is MedianConfig)
                {
                    MedianConfig config = o as MedianConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                else if (o is SobelConfig)
                {
                    SobelConfig config = o as SobelConfig;
                    item.SubItems[0].Text = index++.ToString();
                    item.SubItems.Add(config.Name);
                    item.Tag     = config;
                    item.Checked = config.Enable;
                }
                listView1.Items.Add(item);
            }
        }
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripItem tsi  = sender as ToolStripItem;
            ListViewItem  item = new ListViewItem();

            switch (tsi.Text)
            {
            case "膨胀":
                DilateConfig dc = new DilateConfig();
                imgEvent.config.CfgGroup.Add(dc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(dc.Name);
                item.SubItems.Add(dc.Width.ToString() + "," + dc.Height.ToString());
                item.Tag = dc;
                break;

            case "腐蚀":
                ErodeConfig ec = new ErodeConfig();
                imgEvent.config.CfgGroup.Add(ec);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(ec.Name);
                item.SubItems.Add(ec.Width.ToString() + "," + ec.Height.ToString());
                item.Tag = ec;
                break;

            case "开运算":
                OpenConfig oc = new OpenConfig();
                imgEvent.config.CfgGroup.Add(oc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(oc.Name);
                item.SubItems.Add(oc.Width.ToString() + "," + oc.Height.ToString());
                item.Tag = oc;
                break;

            case "闭运算":
                CloseConfig cc = new CloseConfig();
                imgEvent.config.CfgGroup.Add(cc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(cc.Name);
                item.SubItems.Add(cc.Width.ToString() + "," + cc.Height.ToString());
                item.Tag = cc;
                break;

            case "二值化":
                ThresholdConfig tc = new ThresholdConfig();
                imgEvent.config.CfgGroup.Add(tc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(tc.Name);
                switch (tc.Mode)
                {
                case ThresholdConfig.MyThresholdMode.Auto:
                    item.SubItems.Add("Auto");
                    break;

                case ThresholdConfig.MyThresholdMode.Absolute:
                    item.SubItems.Add(tc.AbsoluteValue.ToString());
                    break;

                case ThresholdConfig.MyThresholdMode.Relative:
                    item.SubItems.Add(tc.RelativeValue.ToString());
                    break;

                default:
                    break;
                }

                item.Tag = tc;
                break;

            case "亮度调节":
                GainOffsetConfig gc = new GainOffsetConfig();
                imgEvent.config.CfgGroup.Add(gc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(gc.Name);
                item.SubItems.Add(gc.Gain.ToString() + "," + gc.Offset.ToString());
                item.Tag = gc;
                break;

            case "旋转":
                RoataeConfig rc = new RoataeConfig();
                imgEvent.config.CfgGroup.Add(rc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(rc.Name);
                item.SubItems.Add(rc.Value.ToString());
                item.Tag = rc;
                break;

            case "中值运算":
                MedianConfig mc = new MedianConfig();
                imgEvent.config.CfgGroup.Add(mc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(mc.Name);
                item.Tag = mc;
                break;

            case "Sobel运算":
                SobelConfig sc = new SobelConfig();
                imgEvent.config.CfgGroup.Add(sc);
                item.SubItems[0].Text = index++.ToString();
                item.SubItems.Add(sc.Name);
                item.Tag = sc;
                break;

            default:
                break;
            }
            item.Checked = true;

            listView1.Items.Add(item);
            Run();
        }