0

My program is CAD type software in which I use OpenTK for graphics. The program works as intended - with one exception. I want to allow the user to change the color of things rendered starting with the background color. To do this I created a second userform (BTW this is a windows.forms program) to allow the user to specify the color by RGB component. I have a return function in the userform that returns Color4. From what I can tell everything works as expected - well kind of...

To simplify I included a bit of code below - which doesn't work. _newColor does capture the correct data, however, when it is passed to ClearColor then Invalidated my Form1 clientwindow shows a big red X.

    private void button2_Click(object sender, EventArgs e)
    {
        Form2 f2tmp = new Form2();
        f2tmp.ShowDialog();
        Color4 _newColor = f2tmp.getColor();
        f2tmp.Dispose();
        GL.ClearColor(_newColor);
        glControl1.Invalidate();
    }

The problem has something to do with the second userform (Form2). If I change the code to this it works:

    private void button2_Click(object sender, EventArgs e)
    {
        Form2 f2tmp = new Form2();
        //f2tmp.ShowDialog();
        //Color4 _newColor = f2tmp.getColor();
        //f2tmp.Dispose();
        Color4 _newColor = new Color4(1f, 0f, 1f, 1f);
        GL.ClearColor(_newColor);
        glControl1.Invalidate();
    }

So that narrows it down to something to do with actually displaying Form2. What gives?

4

1 回答 1

1

这解决了问题:

    private void button2_Click(object sender, EventArgs e)
    {
        Form2 f2tmp = new Form2();
        f2tmp.ShowDialog();
        Color4 _newColor = f2tmp.getColor();
        f2tmp.Dispose();

        // Add this line
        glControl1.MakeCurrent();
        // ta-DA !!! works.

        GL.ClearColor(_newColor);
        glControl1.Invalidate();
    }
于 2013-05-01T15:24:06.627 回答