直接上代码了
 public partial class TestForm : Form
    {
        public TestForm()
        {
            InitializeComponent();
            LoadTheTopMenu();
        }
        #region 
        private void LoadTheTopMenu()
        {
            int w = 0;   //增加宽度            int wl = 0;
            //int hl = 0;            int i = 1;
            for (; i < 3; )
            {
                PictureBox pic_xt_01 = new PictureBox();
                pic_xt_01.Location = new System.Drawing.Point(36 + w, 20);
                pic_xt_01.Name = "pic_xt_0" + i;
                pic_xt_01.Size = new System.Drawing.Size(78, 72);
                pic_xt_01.TabIndex = 2;
                pic_xt_01.TabStop = false;
                pic_xt_01.Image = Properties.Resources.topMenu_01;
                pic_xt_01.Cursor = System.Windows.Forms.Cursors.Hand;
                pic_xt_01.MouseEnter += pic_xt_01_MouseEnter;
                pic_xt_01.MouseLeave += pic_xt_01_MouseLeave;
                pic_xt_01.Click += new EventHandler(pic_xt_01_Click);
                Label lab_xt_01 = new Label();
                lab_xt_01.AutoSize = true;
                lab_xt_01.BackColor = System.Drawing.Color.Transparent;
                lab_xt_01.Location = new System.Drawing.Point(62 + wl, 75);
                lab_xt_01.Name = "lab_xt_0" + i;
                lab_xt_01.Size = new System.Drawing.Size(89, 12);
                lab_xt_01.TabIndex = 1;
                lab_xt_01.Text = "测试";
                lab_xt_01.Cursor = System.Windows.Forms.Cursors.Hand;                panelhead.Controls.Add(lab_xt_01);
                panelhead.Controls.Add(pic_xt_01);
                w = w + 100;
                wl = wl + 100;
                i++;
            }
        }
        private void pic_xt_01_MouseEnter(object sender, EventArgs e)
        {
            setControlBackground((sender as PictureBox), Properties.Resources.topMenu_02);
        }
        private void pic_xt_01_MouseLeave(object sender, EventArgs e)
        {
             setControlBackground((sender as PictureBox), Properties.Resources.topMenu_01);
        }
        private void pic_xt_01_Click(object sender, EventArgs e)
        {
            setControlBackground((sender as PictureBox), Properties.Resources.topMenu_02);
        }
        private void setControlBackground(Control col, Bitmap image)
        {
            col.BackgroundImage = image;
        }
        #endregion
    }

解决方案 »

  1.   

     private void setControlBackground(Control col, Bitmap image)       
     {            col.Image = image;       
     }都用Image属性赋值
      

  2.   

    private void setControlBackground(Control col, Bitmap image)       
      {            (col as PictureBox).Image = image;       
      }
     
      

  3.   

    是的呀。我设置了  pic_xt_01.BackColor=Color.Transparent;但不起作用呀
      

  4.   

     this.Controls.Add(lab_xt_01);
                    this.Controls.Add(pic_xt_01);
                    lab_xt_01.Parent = pic_xt_01;
                    lab_xt_01.Location = new System.Drawing.Point(62 + wl, 75);//注意别超出picturebox的size
                    lab_xt_01.BackColor = System.Drawing.Color.Transparent;
      

  5.   


    如果要实现背景透明为何不用Panel呢?Panel就可以背景透明,但像这种东西,个人感觉还是自定义控件比较好,最起码效率高,然后自己想要什么样的效率就都可以实现,不受自带控件的限制。
    下以文章可以作为参考:
    http://bbs.csdn.net/topics/390332398
      

  6.   


    自己解决问题了吗?没有的话,我给你两个例子,其中一个我曾经模仿QQ的Tab,直接继承TabControl重绘的,另一个是别人写的,直接从ContainerControl类继承写的一个。没解决的话留个邮箱我就发给你