Diedre
Diedre

Reputation: 555

Write in a TextBox inside a function

Im working with Kinect and measuring speed of joints. I have an method to measure the speed, and i want to write it in a text box in the GUI of the kinect application.

How can i do that inside my function? How can i pass the TextBox as an parametrer to the function?

public void Velocity(double[] doub)
{
    double speed;
    // MY CODE for speed aquisiction
    speed = deltax/deltat //the deltas are calculated above, no need to show it here
    Boxname.Text = speed.ToString(); //i want this to work inside the method
}

Upvotes: 0

Views: 193

Answers (1)

Sachin
Sachin

Reputation: 40970

Passing Textbox is not a very good option. As you are creating a function so it would be more meaningful that function does its work and return calculated value. So wherever I required to get the value, I can get by simply calling a function.

In this way I can use the value in whatever purpose I would like e.g. setting the text of textbox.

It would be great if you do something like this

public double Velocity(double[] doub)
{
    double speed;
    // MY CODE for speed aquisiction
    speed = deltax/deltat //the deltas are calculated above, no need to show it here
    return speed;
}

// update the text of textbox by calling the function wherever required.
Boxname.Text = Velocity().ToString();

Upvotes: 2

Related Questions