1

I have two forms (in the same namespace), Form1 which acquires data from images, and GraphForm, which sould plot the data as a surface graph, using the ILNumerics framework.

I had never done such a construction with two forms (fairly new to C#, and coding as a whole for that matters), and I can't figure out why my code doesn't work, as it's almost copy/pasted from a previous question asked here (Sujith H S answer). I tried other constructions described in various similar questions as well, with the same result : the second form and the ILNumerics plotting interface appear, but are empty.

Here is my version of the answer I linked :

IN FORM1 :

// Form creation
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    public static ILInArray<double> CrossCorrExpMatrixReShiftedILN;

    //Here is my whole data acquisition code, about 800 lines long

    ILInArray<double> CrossCorrExpMatrixReShiftedILN = CrossCorrExpMatrixReShifted;

    GraphForm Form2 = new GraphForm();
    Form2.Show();

IN GRAPHFORM :

public partial class GraphForm : Form
{
    public GraphForm()
    {
        InitializeComponent();
    }

    private void GraphForm_Load(object sender, EventArgs e)
    {
        ILInArray<double> GraphData = Form1.CrossCorrExpMatrixReShiftedILN;
        //Here I use GraphData to plot the surface
    }

Does anyone have an idea why it doesn't work ?

Trion
  • 115
  • 11
  • Please provide a little bit more information about what exactly *"doesn't work"*... i.e. What are you actually trying to do? Do you get any exceptions or errors? What did you expect your code to do, and what does it actually do? Where does it fail / what exactly *"doesn't work*"? – bassfader Apr 27 '18 at 09:17
  • Sorry I had the feeling my problem was pretty clear. I want to plot a surface using ILNumerics in `GraphForm`using data acquired form `Form1`. The code I provided doesn't return an exception, it runs flawlessly, but I end up with a blank ILNumerics plotting interface in GraphForm. – Trion Apr 27 '18 at 09:58

2 Answers2

2

Have you tried passing the ILInArray<double> object into GraphForm's constructor and setting it to a local variable? So something like the below?

IN FORM1 :

GraphForm Form2 = new GraphForm(CrossCorrExpMatrixReShiftedILN);
Form2.Show();

IN GRAPHFORM :

public partial class GraphForm : Form
{
    private ILInArray<double> CrossCorrExpMatrixReShiftedILN;

    public GraphForm(ILInArray<double> pCrossCorrExpMatrixReShiftedILN)
    {
        InitializeComponent();
        CrossCorrExpMatrixReShiftedILN = pCrossCorrExpMatrixReShiftedILN;
    }

    private void GraphForm_Load(object sender, EventArgs e)
    {
        ILInArray<double> GraphData = CrossCorrExpMatrixReShiftedILN;
        //Here I use GraphData to plot the surface
    }
ataraxia
  • 995
  • 13
  • 31
  • I just tried your version, but the result is the same : I end up with a blank ILNumerics plotting interface in Form2. – Trion Apr 27 '18 at 09:55
  • Try changing the `CrossCorrExpMatrixReShiftedILN` variable in Form1 so that it is non-static? Have you put a breakpoint on GraphForm's constructor to check that the received parameter actually has data? – ataraxia Apr 27 '18 at 10:00
  • Doesn't work ! What do you mean by "breakpoint" ? I never used that. – Trion Apr 27 '18 at 10:07
  • Presuming you are using Visual Studio (other IDEs should have the same facility but I've not used them), you can left-click in the code margin on the left so that when your application reaches that point in code it will pause until you start it again. Put a breakpoint within GraphForm's constructor and hover over pCrossCorrExpMatrixReShiftedILN to see if there is any data in it. See here >> https://www.c-sharpcorner.com/UploadFile/pranayamr/setting-breakpoints-in-visual-studio/ – ataraxia Apr 27 '18 at 10:11
  • I found the problem ! Thanks for your help, I'm going to answer my own question. – Trion Apr 27 '18 at 12:54
1

I found the solution.

In the design tab for the GraphForm form, the Load event was NOT associated with the GraphForm_Load code bit. I don't know why it didn't associate automatically.

I found this by placing breakdown points along the GraphForm code, and noticing that the GraphForm_Load code didn't run at all.

Trion
  • 115
  • 11