日期:2014-05-17  浏览次数:21877 次

c#中在picturebox中画线

Bitmap bmp = new Bitmap(this.pictureBox1.ClientRectangle.Width, this.pictureBox1.ClientRectangle.Height);
            Graphics g = Graphics.FromImage(bmp);
            g.DrawImage(bmp, this.pictureBox1.Location.X, this.pictureBox1.Location.Y);
            Color cb = Color.FromArgb(255, 255, 255);
            for (int i = 0; i < this.pictureBox1.Width; i++)
            {
                for (int j = 0; j < this.pictureBox1.Height; j++)
                {
                    bmp.SetPixel(i, j, cb);
                }
            }
            Pen black_pen = new Pen(Color.Black, 3);
            Pen think_pen = new Pen(Color.Black, 1);
            // g.DrawLine(black_pen, zero_x, zero_y, zero_x + 10, zero_y + 10); 
            len_cor_x = zero_x + width;
            len_cor_y = zero_y + height;
            g.DrawLine(black_pen, zero_x, len_cor_y, len_cor_x, len_cor_y);//x坐标轴
            //g.DrawLine(black_pen, zero_x, zero_y, zero_x, zero_y + height);//y轴坐标
            //g.DrawLine(black_pen, new Point(zero_x, zero_y), new Point(zero_x, zero_y + height));//y轴坐标


            g.DrawImage(bmp, this.pictureBox1.Location.X, this.pictureBox1.Location.Y);
            this.pictureBox1.Image = bmp;
            if (this.pictureBox1.Image == null)
                MessageBox.Show("no image");
            
            this.pictureBox1.Invalidate();
            g.Dispose();

其中,zero_x=zero_y=0;height是高度,width是宽度

具体问题详见这里
http://bbs.csdn.net/topics/390566639

picturebox的size=400*200,位置在form中的250,12处。当在form中位置改变时候,多余的那个竖线也会相应改变,当向下到一定位置的时候,可以正常显示。

这个情况怎么解释啊,我需要吧picturebox放在form中的250,1