I'm developing a solution where I have a Windows Form, where I've placed a pictureBox. I want to move it through the screen depending on the value of pressure center I have already calculated.
I instantiated a class called pressureCenterManager that makes all the functionalities.
So, in my form code I have the following:
pressureCenterManager.displayPressureCenter(pressureMatrix, this.plot, this.pbox_CoG);
I get a correct value in the var pressureCenter.
This is my code in the displayPressureCenter function:
public void displayPressureCenter(double[,] pressureMatrix, Plot plot, PictureBox pictureBox)
{
//Get matrix size
int xSize = pressureMatrix.GetLength(0);
int ySize = pressureMatrix.GetLength(1);
try
{
//Get CoP and move pictureBox
System.Windows.Point centerOfPressure = getCenterOfPressure(pressureMatrix);
pictureBox.Visible = true;
pictureBox.Parent = plot.plotView;
//Calculamos el punto dónde hay que printar utilizando una regla de 3 y descontando la mitad del tamaño de la señal (para que quede centrada)
System.Drawing.Point displayPositionCart = new System.Drawing.Point((int)Math.Round((centerOfPressure.X * plot.plotView.Width / xSize) - (pictureBox.Width / 2)), (int)Math.Round((centerOfPressure.Y * plot.plotView.Height / ySize) - (pictureBox.Height / 2)));
//Pasamos a coordenadas de pantalla y aplicamos un offset para quitar el eje
System.Drawing.Point displayPositionScre = CartesianToScreenCoordinates(displayPositionCart, plot.plotView);
displayPositionScre.Offset(0, -70);
pictureBox.Location = displayPositionScre;
}
catch
{
}
I don't know why, when executing pictureBox.Visible = true; it jumps to the catch section.
Can you please help me?
Many thanks!