Results 1 to 19 of 19

Thread: PictureBox: Scale Width & Height

Threaded View

  1. #14
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: PictureBox: Scale Width & Height

    Add this on Top (Form level)
    Code:
       private int mScaleWidth  = 5600;
       private int mScaleHeight = 5356;
    Then this is the Paint Event named PaintIt (you can use another name) and a drawLine sub, use this one instead of e.Graphics.DrawLine
    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);
    	}
    That should draw a Square using your coordinate system.
    Last edited by jcis; Jan 17th, 2007 at 01:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width