Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows forms application that does the following:
- 6 buttons to increment or decrement X, Y, Z values
- when a button is clicked, the program calculates a robot configuration to this values
- the program displays the values and configuration in several text boxes

I have also created a OpenGL paint event which draws the configuration.
Now, I need to redraw the configuatrion every time 1 of the 6 is clicked. (In other words, how can I call an event when another event is called by an action - like a button click)

Posted

Put your opengl painting code in a function, and call it from the button click events and the opengl paint event.

Here's some rough pseudo code:

int _x, _y, _z;

// Properties
public int X
{
    get { return _x; }
    set { _x = value; UpdateConfiguration(); }
}

public int Y
{
    get { return _y; }
    set { _y = value; UpdateConfiguration(); }
}

public int Z
{
    get { return _z; }
    set { _z = value; UpdateConfiguration(); }
}

// Methods
void UpdateConfiguration()
{
    // Update your text boxes here

    // Redraw whatever you need to redraw
    DrawConfiguration();
}

void DrawConfiguration()
{
    // Do your openGL stuff here
}

// Event handlers
void IncX_Click(...)
{
    X += 1;
}

void DecX_Click(...)
{
    X -= 1;
}


void IncY_Click(...)
{
    Y += 1;
}

void DecY_Click(...)
{
    Y -= 1;
}

void IncZ_Click(...)
{
    Z += 1;
}

void DecZ_Click(...)
{
    Z -= 1;
}

void OpenGL_PaintEvent(...)
{
    DrawConfiguration();
}
 
Share this answer
 
using (Font myFont = new Font("Arial", 14)) { e.Graphics.DrawString("Hello .NET Guide!", myFont, Brushes.Green, new Point(2, 2)); }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900