I have a windows application.
[
^]
When I click on Calculate, I make some calculations using those textboxes.
with those calculations, I obtain some values and write them on a datagridview
[
^]
At this point, I need to draw some lines using those values which are basically coordinates of my points..
Some people told me to create a picturebox and create a paint event.
Therefore I tried this;
Pen myPen = new Pen(Color.Black);
private void pictureBoxDraw_Paint(object sender, PaintEventArgs e)
{
myPen.Width = 2;
if (binary > 0)
{
Point point1 = new Point(10, 20);
Point point2 = new Point(10, 40);
e.Graphics.DrawLine(myPen, point1, point2);
}
else
{
}
}
private void buttonDraw_Click_1(object sender, EventArgs e)
{
binary = 1;
pictureBoxDraw.Invalidate();
}
private void buttoncleardraw_Click(object sender, EventArgs e)
{
binary = 0;
pictureBoxDraw.Invalidate();
}
When I change
Point point1 = new Point(10, 20);
to
Point point1 = new Point(Convert.ToInt32(dataGridViewCrestGeo.Rows[0].Cells[0].Value), Convert.ToInt32(dataGridViewCrestGeo.Rows[0].Cells[0].Value));
I obtain an error message like this
[
^]
I need to find a way to draw these lines when I click on the Draw button.
I am a civil engineer and all these things are really complicated for me. I would appreciate any kind of help. Thanks.
What I have tried:
Pen myPen = new Pen(Color.Black);
private void pictureBoxDraw_Paint(object sender, PaintEventArgs e)
{
myPen.Width = 2;
if (binary > 0)
{
Point point1 = new Point(Convert.ToInt32(dataGridViewCrestGeo.Rows[0].Cells[0].Value), Convert.ToInt32(dataGridViewCrestGeo.Rows[0].Cells[0].Value));
Point point2 = new Point(10, 40);
e.Graphics.DrawLine(myPen, point1, point2);
}
else
{
}
}
private void buttonDraw_Click_1(object sender, EventArgs e)
{
binary = 1;
pictureBoxDraw.Invalidate();
}
private void buttoncleardraw_Click(object sender, EventArgs e)
{
binary = 0;
pictureBoxDraw.Invalidate();
}