如图,我把label的背景色设置为了透明label1.BackColor = Color.Transparent;
为什么画的直线,还是没有穿过label控件,前次,我试过都行,今天为什么不行了呢,奇怪?

解决方案 »

  1.   

    穿过???
    之前你是先Label后画线的吧?而这次你是先画线后放Label的吧??
      

  2.   

    你看下是不是有一个ZIndex的属性,值越大,显示越在前
      

  3.   

    ZIndex?哪里?
    我这次还是先label,后画线的
      

  4.   

    label1.BackColor = Color.Transparent;
    此代码没有起作用,你代码怎么写的?
      

  5.   

     private void Form1_Load(object sender, EventArgs e)
            {
              label1.BackColor = Color.Transparent;
            }
     private void Form1_Paint(object sender, PaintEventArgs e)
           {
                Graphics graphics = this.CreateGraphics();
                Pen pen1 = new Pen(Color.Gray, 1);
                int x = label1.Location.X - 5;
                int y = label1.Location.Y + 20;
                graphics.DrawLine(pen1, x - 20, y, x + 30, y);
            }label1是拖上去的
      

  6.   


     Graphics graphics = this.CreateGraphics();
      Pen pen1 = new Pen(Color.Gray, 1);
      int x = label1.Location.X - 5;
      int y = label1.Location.Y + 20;
      graphics.DrawLine(pen1, x - 20, y, x + 30, y);替换为如下:
     e.Graphics.DrawLine(Pens.Gray, 28, 180, 300, 180);你这么代码问题很大
      

  7.   

    1.在private void Form1_Paint(object sender, PaintEventArgs e)事件里面不需要创建图形类
      方法已经给你了,且不要释放这个图形对象.2.this.CreateGraphics();使用后必须释放.
      

  8.   

    Transparent:透明,什么时候起作用?
      

  9.   

    你这个label干鸟用,需要点击?
    为何不自己画框?
      

  10.   

    拖一个label1到窗口
    private void Form1_Load(object sender, EventArgs e)
      {
      label1.BackColor = Color.Transparent;
      }
     private void Form1_Paint(object sender, PaintEventArgs e)
      {
      Graphics graphics = e.Graphics;
      //Graphics graphics = this.CreateGraphics();
      Pen pen1 = new Pen(Color.Gray, 1);
      int x = label1.Location.X ;
      int y = label1.Location.Y ;
      graphics.DrawLine(pen1, x - 20, y+20, x + 30, y+20); 
     }
    情况是这样的,
    在Form1_Paint中,如果在写成Graphics graphics = e.Graphics;直线就能穿过label1;
    如果写成Graphics graphics = this.CreateGraphics();不会报错,但不能穿过label1;
    是什么原因?请问