Why a graphics overflow problem as a result of a for loop?

Posted by sonny5 on Stack Overflow See other posts from Stack Overflow or by sonny5
Published on 2010-03-25T04:23:47Z Indexed on 2010/03/25 4:33 UTC
Read the original article Hit count: 392

Filed under:

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Drawing.Imaging; using System.Drawing.Drawing2D;

public class Form1 : System.Windows.Forms.Form {

public static float WXmin;
public static float WYmin;
public static float WXmax;  
public static float WYmax;  
public static int   VXmin;
public static int   VYmin;
public static int   VXmax;
public static int   VYmax; 
public static float Wx;
public static float Wy; 
public static float Vx; 
public static float Vy;

public Form1()
{
  InitializeComponent();
}

private void InitializeComponent()
{
  this.ClientSize = new System.Drawing.Size(400, 300);
  this.Text="Pass Args";
  this.Paint += new System.Windows.Forms.PaintEventHandler(this.doLine);
  //this.Paint += new System.PaintEventHandler(this.eachCornerPix); 
  //eachCornerPix(out Wx, out Wy, out Vx, out Vy); 
}

static void Main() 
{
  Application.Run(new Form1());
}

private void doLine(object sender, System.Windows.Forms.PaintEventArgs e)
{
  Graphics g = e.Graphics;
  g.FillRectangle(Brushes.White, this.ClientRectangle);
  Pen p = new Pen(Color.Black);
  g.DrawLine(p, 0, 0, 100, 100);  // draw DOWN in y, which is positive since no matrix called
  eachCornerPix(sender, e, out Wx, out Wy, out Vx, out Vy); 
  p.Dispose();
}

private void eachCornerPix (object sender, System.EventArgs e, out float Wx, out float Wy, out float Vx, out float Vy)
{
  Wx = 0.0f;
        Wy = 0.0f;
        Vx = 0.0f;
        Vy = 0.0f;
  Graphics g = this.CreateGraphics();
  Pen penBlu = new Pen(Color.Blue, 2);
  SolidBrush redBrush = new SolidBrush(Color.Red);
  int width = 2;    // 1 pixel wide in x
  int height = 2;
  float [] Wxc = {0.100f, 5.900f, 5.900f, 0.100f}; 
  float [] Wyc = {0.100f, 0.100f, 3.900f, 3.900f}; 
  Console.WriteLine("Wxc[0] = {0}", Wxc[0]);
  Console.WriteLine("Wyc[3] = {0}", Wyc[3]);
  /*
  for (int i = 0; i<3; i++)
  {
    Wx = Wxc[i];
    Wy = Wyc[i];
    Vx = ((Wx - WXmin)*((VXmax-VXmin)+VXmin)/(WXmax-WXmin));  
        Vy = ((Wy - WYmin)*(VYmax-VYmin)/(WYmax-WYmin)+VYmin); 
        Console.WriteLine("eachCornerPix Vx= {0}", Vx);
        Console.WriteLine("eachCornerPix Vy= {0}", Vy);
        g.FillRectangle(redBrush, Vx, Vy, width, height);
  }  
  */

  // What is there about this for loop that will not run?
  // When the comments above and after the for loop are removed, it gets an overflow?
  g.Dispose();

}

}

© Stack Overflow or respective owner

Related posts about c#