为什么以下代码显示不了我要加入的picturebox?
PictureBox pb = new PictureBox();
pb.Location = new System.Drawing.Point(176,72);
pb.Size = new Size(80,13);
pb.BorderStyle = BorderStyle.None;
Graphics g1 = pb.CreateGraphics();
g1.FillRectangle(Brushes.BlueViolet,180,73,50,7);this.Controls.Add(pb);this.Refresh();

解决方案 »

  1.   

    我倒。。 背景色的问题 但以下的代码没用,,怎么办。。

    Graphics g1 = pb.CreateGraphics();
    g1.FillRectangle(Brushes.BlueViolet,180,73,50,7);
      

  2.   

    PictureBox pb = new PictureBox();
                pb.Location = new System.Drawing.Point(176, 72);
                pb.Size = new Size(80, 13);
                pb.BorderStyle = BorderStyle.FixedSingle;
                Graphics g1 = pb.CreateGraphics();
                g1.FillRectangle(Brushes.BlueViolet, 0, 0, 50, 7);            this.Controls.Add(pb);            this.Refresh();这就看得到了
      

  3.   

    Graphics g1 = pb.CreateGraphics();
    g1.FillRectangle(Brushes.BlueViolet,180,73,50,7);
    你画上去后 pb一重绘东西就没有了可以重载下PictureBox把Graphics g1 = pb.CreateGraphics();
    g1.FillRectangle(Brushes.BlueViolet, 0, 0, 50, 7);写到OnPaint里面
      

  4.   

    或者简单点 pb.OnPaint+= new 你的事件
      

  5.   

    谢谢g1.FillRectangle(Brushes.BlueViolet, 0, 0, 50, 7),这里的参数是相对picurebox?我以为要相对窗体呢?pb.OnPaint+= new 没有这东西啊,系统没提示,强行写?