本文介绍了c# - 重复tabbpage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我想在xmpp中使用会话标签,Emotion面板开发一个迷你Messaenger。

我可以通过单击表单中的添加按钮来复制tabpage。当我复制2,或... tabpage。当我单击显示面板时,面板在我当前的标签页中不可见,并且在其他标签页中可见(在最后一个标签页中),我上传了我的项目:



[ ]



帮我解决问题









hi i want to develop a mini messaenger in xmpp with conversation tabpage, Emotion panel.
i can duplicate tabpage by clicking " Add " button in my form. when i duplicate 2,or ... tabpage . and when i click show panel, panel dont visible in my current tabpage and visible in other tabpage(in last tabpage), i uploaded my project :

http://www.megafileupload.com/en/file/541739/tabpage-rar.htm[^]

help me to slove problem




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 tabpage
{
    public partial class Form1 : Form
    {
        private System.Windows.Forms.Panel pan;
        private System.Windows.Forms.Button bt;
        private System.Windows.Forms.PictureBox im1;
        private System.Windows.Forms.PictureBox im2;
        private System.Windows.Forms.PictureBox im3;
        private System.Windows.Forms.TabPage tp;


        public Form1()
        {
            InitializeComponent();
        }

        private void duplicate()
        {


            this.pan = new System.Windows.Forms.Panel();
            this.bt = new System.Windows.Forms.Button();
            this.im1 = new System.Windows.Forms.PictureBox();
            this.im2 = new System.Windows.Forms.PictureBox();
            this.im3 = new System.Windows.Forms.PictureBox();
            this.tp = new System.Windows.Forms.TabPage();
            //
            pan.Location = new Point(201, 6);
            pan.Size = new Size(140, 146);
            pan.BackColor = Color.Gray;
            pan.Visible = false;
            //
            bt.Location = new Point(235, 158);
            bt.Text = "show";
            this.bt.Click += new System.EventHandler(this.bt_Click);
            //
            im1.Size = new Size(25, 25);
            im1.Location = new Point(3, 3);
            im1.Image = Properties.Resources._16_circle_green;
            im1.SizeMode = PictureBoxSizeMode.CenterImage;
            //
            im2.Size = new Size(25, 25);
            im2.Location = new Point(30, 3);
            im2.Image = Properties.Resources.delete__166_;
            im2.SizeMode = PictureBoxSizeMode.CenterImage;
            //
            im3.Size = new Size(25, 25);
            im3.Location = new Point(57, 3);
            im3.Image = Properties.Resources.down;
            im3.SizeMode = PictureBoxSizeMode.CenterImage;

            //

            tp.Controls.Add(pan);
            tp.Controls.Add(bt);
            pan.Controls.Add(im1);
            pan.Controls.Add(im2);
            pan.Controls.Add(im3);
            tabControl1.Controls.Add(tp);

        }
        private void bt_Click(object sender, System.EventArgs e)
        {
            if (bt.Text == "show")
            {
                pan.Visible = true;
                bt.Text = "hide";
            }
            else if (bt.Text == "hide")
            {
                pan.Visible = false;
                bt.Text = "show";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            duplicate();
        }
    }
}





image: []

推荐答案

this.pan = new System.Windows.Forms.Panel();
this.bt = new System.Windows.Forms.Button();
this.im1 = new System.Windows.Forms.PictureBox();
this.im2 = new System.Windows.Forms.PictureBox();
this.im3 = new System.Windows.Forms.PictureBox();
this.tp = new System.Windows.Forms.TabPage();



因此,当您尝试使面板上的项目可见或不可见时:


So when you try to make items on a panel visible or invisible:

private void bt_Click(object sender, System.EventArgs e)
 {
     if (bt.Text == "show")
     {
         pan.Visible = true;
         bt.Text = "hide";
     }
     else if (bt.Text == "hide")
     {
         pan.Visible = false;
         bt.Text = "show";
     }
 }

您将始终只生成您创建的最新版本。

删除类级别变量 - 并且只能通过以下方式访问控件当前选择的标签页:应该修复它。



顺便说一句:如果你将按钮和图片框放到UserControls上,你会让生活变得更轻松,然后使用它而不是面板 - 它们会在您创建UserControl实例并将其添加到标签页时自动显示。

You will always effect only the latest version you have created.
Drop the class level variables - and only ever access the controls via teh currently selected tab page: that should fix it.

BTW: You would make your life a lot, lot easier if you put your button and picture boxes onto a UserControls, and then used that instead of a panel - they would automatically appear when you created the UserControl instance and added that to the tab page.


这篇关于c# - 重复tabbpage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:27