Radu Negres

Radu Negres

  • NA
  • 2
  • 666

Input string was not in a correct format?

Nov 18 2017 6:21 PM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
static int start_x = 0, start_y = 0;
static int end_x = 0, end_y = 0;
Graphics g = null;
Pen p = new Pen(Color.Red);
static int my_angle = 0, my_lenght = 0, my_increment = 0, num_lines = 0;
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
public Form1()
{
InitializeComponent();
start_x = canvas.Width / 2;
start_y = canvas.Height / 2;
}
private void drawLines()
{if(String.IsNullOrWhiteSpace(angle.Text))
my_angle = my_angle + Int32.Parse(angle.Text);
my_lenght = my_lenght + Int32.Parse(increment.Text);
end_x = (int)(start_x + Math.Cos(my_angle* .017453292519) * my_lenght);
end_y = (int)(start_y + Math.Sin(my_angle* .017453292519) * my_lenght);
Point[] points = { new Point(start_x, start_y), new Point(end_x, end_y) };
start_y = end_y;
start_x = end_x;
g.DrawLines(p, points);
}
private void button1_Click(object sender, EventArgs e)
{
my_angle = Int32.Parse(angle.Text);
my_lenght = Int32.Parse(lenght.Text);
my_increment = Int32.Parse(increment.Text);
start_x = canvas.Width / 2;
start_y = canvas.Height / 2;
canvas.Refresh();
}
private void canvas_Paint(object sender, PaintEventArgs e)
{
g = canvas.CreateGraphics();
my_lenght = Int32.Parse(lenght.Text);
p.Width = 1;
for (int i = 0; i < Int32.Parse(nrlinii.Text);i++)
drawLines();
}
}
}
This is my code,the error ocurs at my_angle = Int32.Parse(angle.Text);
There is a string value in angle.Text,i have no idea why it would not work. 

Answers (2)