Dear All,
I am stuck with my project a little bit and I need a little help. I am using Visual Studio 2017, for C#.
Basically my problem is that I cannot access an array in Form2 that is produced in the Form1. But the problem is a bit funny. I generate a matrix in Form1 that will be used as a bitmap in Form2. So I generate some matrix in Form1 based on some experimental data, and then I can pass this array and the number of its cols and rows to Form2 and then I can show it there as a bitmap picture.
I also have a small piece of code that shows the X and Y coordinates of the image if I click on it. This is very important for me, because based on these coordinates, I can look up values in different other arrays. I have one array that is making up the picture as a bitmap, but I assign many other data for each pixel and I want to store them in different arrays.
What is the easiest way to make an array and its values visible in Form2? I don't want to edit the arrays from Form2, I just want to be able to read them. So when I click on the picture, I can look up the values corresponding for the coordinates.
Thank you for the help and advice!
What I have tried:
In Form1, this part of the code works:
Form2 newForm2 = new Form2();
newForm2.ShowSLImg(ROWS, COLUMNS, array2D);
newForm2.Show(this);
Then in Form2, I use a function:
public void ShowSLImg(int _row, int _column, double[,] aarray2D)
{...dosomething...}
So I am able to pass the array2D and ROWS, COLUMNS to the Form2 and I can work with it and based on the array2D values, I am able to show a bitmap image in the Form2.
In this part of the code, I can fetch the coordinates of the mouse position and also I can do something based on the color. But I would like to extend this function and be able to look up different array based on the x,y coordinates.
public void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
Color color = image2.GetPixel(e.X, e.Y);
double Red = color.R;
label1.Text = (Red / 255).ToString();
int _x = Convert.ToInt32(e.X);
int _y = Convert.ToInt32(e.Y);
TextBox.Text += "X: "+_x.ToString() + " Y: " + _y.ToString() +Environment.NewLine;
}