我想在在两个指定的单元格中绘制一条直线,我使用下面的语句就是没效果,唉!
例如:我想绘在dataGridView2[0, 1]和dataGridView2[1, 5] 之间绘一绿色的直线。   private void dataGridView2_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
e.Graphics.DrawLine( new Pen(Brushes.Green,3), dataGridView2[0, 1].ContentBounds.Location, dataGridView2[1, 2].ContentBounds.Location);
        }

解决方案 »

  1.   

    厉害  连COM 都结婚了
      

  2.   

    计算两个端点坐标,自己DrawLine。。
      

  3.   

    e.Graphics.DrawLine( new Pen(Brushes.Green,3), dataGridView2[0, 1].ContentBounds.Location, 
    dataGridView2[1, 2].ContentBounds.Location); 
    为什么这样就是不行啊?!
      

  4.   

    没有加e.Handled=true他绘制的覆盖掉你的
      

  5.   

    怎么就没人回呢,我是想实现
    http://www.500wan.com/pages/info/datachart/ssq/zoushi/bluezs_1.shtml
    这个里面一样的效果,不过绘制直线是在dataGridView 中。
      

  6.   

       private void drawline(DataGridViewCell c1, DataGridViewCell c2)
            {
                Graphics g = this.dataGridView1.CreateGraphics();            Point p1 = this.dataGridView1.GetCellDisplayRectangle(c1.ColumnIndex, c1.RowIndex, false).Location;
                Point p2 = this.dataGridView1.GetCellDisplayRectangle(c2.ColumnIndex, c2.RowIndex, false).Location;
                p1.Offset(c1.Size.Width / 2, c1.Size.Height / 2);
                p2.Offset(c2.Size.Width / 2, c2.Size.Height / 2);
                g.DrawLine(Pens.Blue, p1, p2);
            }
      

  7.   

    ContentBounds是指单元格里的内容的大小位置,且是相对于单元格而言。