Add this on Top (Form level)
Then this is the Paint Event named PaintIt (you can use another name) and a drawLine sub, use this one instead of e.Graphics.DrawLineCode:private int mScaleWidth = 5600; private int mScaleHeight = 5356;
That should draw a Square using your coordinate system.Code:private void PaintIt(object sender, System.Windows.Forms.PaintEventArgs e) { PB1.BackColor = System.Drawing.Color.White; //Square drawLine(e.Graphics, Pens.Black , 1000, 1000, 2000, 1000); drawLine(e.Graphics, Pens.Black, 2000, 1000, 2000, 2000); drawLine(e.Graphics, Pens.Black, 2000, 2000, 1000, 2000); drawLine(e.Graphics, Pens.Black, 1000, 2000, 1000, 1000); } private void drawLine(Graphics Gr,Pen Pn, int X1, int Y1, int X2, int Y2) { int ScaledX1 = (int) (((float) X1 / mScaleWidth) * PB1.ClientSize.Width); int ScaledX2 = (int) (((float) X2 / mScaleWidth) * PB1.ClientSize.Width); int ScaledY1 = (int) (((float) Y1 / mScaleHeight) * PB1.ClientSize.Height); int ScaledY2 = (int) (((float) Y2 / mScaleHeight) * PB1.ClientSize.Height); Gr.DrawLine (Pens.Black ,ScaledX1, ScaledY1, ScaledX2,ScaledY2); }




Reply With Quote