I have a form with winForms and c # where I have two pictureboxes and some textboxes that fill in these values generate a graphic joining the points x1 - > x2 ... then x2 - > x3 and so on. The code I have is this.
In the textChanged event of the textbox I have this code
private void modificarDatos_Audio_OD_TextChanged(object sender, EventArgs e)
{
botonPintarGrafica_Click(null, null);
}
And in the function I have the following
private void botonPintarGrafica_Click(object sender, EventArgs e)
{
int x = 0, y = 0, multiplicador = 42;
int x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0;
int y1 = 0, y2 = 0, y3 = 0, y4 = 0, y5 = 0;
List<DibujoRXModel> listaPuntos = new List<DibujoRXModel>();
DibujoRXModel tonoOD_A = new DibujoRXModel();
tonoOD_A.pos1 = Convert.ToInt32(DataUtils.IntNullToZero(pos1a.Text));
tonoOD_A.pos2 = Convert.ToInt32(DataUtils.IntNullToZero(pos2a.Text));
tonoOD_A.pos3 = Convert.ToInt32(DataUtils.IntNullToZero(pos3a.Text));
listaPuntos.Add(tonoOD_A);
Graphics grafico1;
grafico1 = pictureBox1.CreateGraphics();
grafico1.Clear(Color.LightGreen);
Pen lapiz = new Pen(Color.Red, 2);
foreach (DibujoRXModel tono in listaPuntos)
{
if (tono.pos1 >= 0)
{
x1 = 1 * multiplicador;
y1 = tono.pos1;
grafico1.DrawRectangle(lapiz, new Rectangle(x1, y1, 5, 5));
}
if (tono.pos2 >= 0)
{
x2 = 2 * multiplicador;
y2 = tono.pos2;
grafico1.DrawRectangle(lapiz, new Rectangle(x2, y2, 5, 5));
}
if (tono.pos3 >= 0)
{
x3 = 3 * multiplicador;
y3 = tono.pos3;
grafico1.DrawRectangle(lapiz, new Rectangle(x3, y3, 5, 5));
}
}
grafico1.DrawLine(lapiz, x1, y1, x2, y2);
grafico1.DrawLine(lapiz, x2, y2, x3, y3);
}
This what it does is that as I change the values in the textbox is repainting the graph, the problem I have is that if I move with the mouse between the textbox nothing happens, but if I move with the tabulator between textbox the graphic "disappears" and I do not see the problem where it comes from.