无法使用按钮c#更改活动tabPage

时间:2016-03-02 14:06:52

标签: c# winforms tabcontrol

我有一个名为mtcNewExpTabControl的MetroTabControl,有四个页面(mtpSettings,mtpNewExp,mtpTempImages,mtpCompareImages)。

我正在mtpNewExp页面上启动新实验并在点击" StartExperiment"后获取图像。按钮。用户可以获得许多图像。完成实验后,我将图像添加到 imageList1.Images 。 当我点击mtpTempImages tabPage mtcNewExpTabControl_SelectedIndexChanged 时,会触发图像,并使用以imageList1.Images.Keys [i]命名的组合框显示图像。我可以在mtpTempImages上显示许多组合框和图片框对。

在mtpTempImages上还有一个 mtbCompareImages 按钮。用户可以选中与checboxName命名相同的图片框旁边的复选框。在检查了比较所需的所有复选框后,用户将点击"比较图像"按钮。

我想在不单击选项卡的情况下将活动tabPage更改为mtpCompareImages。 mtbCompareImages 按钮就足够了。我可以在mtpTempImages上显示图像,但我无法在mtpCompareImages标签页上成功。活动tabPage也不会更改为mtpCompareImages tabPage。我该怎么办?

    List<MetroCheckBox> cbxTempImages = new List<MetroCheckBox>();
    List<MetroCheckBox> cbxCompareImages = new List<MetroCheckBox>();
    List<PictureBox> pbxTempImages = new List<PictureBox>();
    List<PictureBox> pbxCompareImages = new List<PictureBox>();

    private void mtbCompareImages_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < cbxTempImages.Count(); i++)
        {
            if (cbxTempImages[i].Checked == true)
            {
                imageListChecked.Images.Add(pbxTempImages[i].Name, pbxTempImages[i].Image);
            }
        }
        this.mtcNewExpTabControl.SelectedTab = mtpCompareImages;

    }

    private void mtcNewExpTabControl_SelectedIndexChanged(object sender, EventArgs e)
    {   

        if((MetroTabPage)this.mtcNewExpTabControl.SelectedTab == mtpTempImages)
        {
            for (int i = 0; i < imageList1.Images.Count; i++)
            {
                cbxTempImages.Add(new MetroCheckBox());

                cbxTempImages[i].Name = imageList1.Images.Keys[i].ToString();
                cbxTempImages[i].Size = new Size(15, 15);
                cbxTempImages[i].BackColor = Color.Transparent;
                cbxTempImages[i].Location = new Point(x, y);

                //PictureBox pic = new PictureBox();
                pbxTempImages.Add(new PictureBox());
                pbxTempImages[i].Name = imageList1.Images.Keys[i].ToString();
                pbxTempImages[i].Image = imageList1.Images[i];
                pbxTempImages[i].SizeMode = PictureBoxSizeMode.StretchImage;
                pbxTempImages[i].Location = new Point(x + 15, y);
                x += 120;
                if (x > this.pnlTempImages.Width - 120)
                {
                    x = 10; y += 100;
                }

                this.pnlTempImages.Controls.Add(cbxTempImages[i]);
                this.pnlTempImages.Controls.Add(pbxTempImages[i]);
            }

        }
        else if((MetroTabPage)this.mtcNewExpTabControl.SelectedTab ==  mtpCompareImages)
        {

            x = 10; y = 10;

            for (int i = 0; i < imageListChecked.Images.Count; i++)
            {
                cbxCompareImages.Add(new MetroCheckBox());
                //MetroCheckBox cbxCI = new MetroCheckBox();
                cbxCompareImages[i].Name = imageListChecked.Images.Keys[i].ToString();
                cbxCompareImages[i].Size = new Size(15, 15);
                cbxCompareImages[i].BackColor = Color.Transparent;
                cbxCompareImages[i].Location = new Point(x, y);
                //PictureBox picCI = new PictureBox();
                pbxCompareImages.Add(new PictureBox());
                pbxCompareImages[i].Name = imageListChecked.Images.Keys[i].ToString();
                pbxCompareImages[i].Image = imageListChecked.Images[i];
                pbxCompareImages[i].SizeMode = PictureBoxSizeMode.StretchImage;
                pbxCompareImages[i].Location = new Point(x + 15, y);
                x += 120;
                if (x > this.pnlCompareImages.Width - 120)
                {
                    x = 10; y += 100;
                }

                this.pnlCompareImages.Controls.Add(cbxCompareImages[i]);
                this.pnlCompareImages.Controls.Add(pbxCompareImages[i]);

            }
        }
        InitializeComponent();
    }

0 个答案:

没有答案