How can I synchronize the values ​​of the NumericUpDown and TrackBar controls in WinForms?

I have a simple Windows Forms application (not WPF), and I have two controls:

  • Trackbar
  • NumericUpDown

I want to make some bindings between them, so if one of them has a change in value, the other control will be updated to show the same value.

Is it possible? If so, how can I do this?

Thank.

+3
source share
1 answer

Of course it is possible. I don’t know how to establish a connection between two automatic controls, so you yourself will write the code. But don’t worry, it’s not difficult.

, . , : ValueChanged. . :

void myNumericUpDown_ValueChanged(object sender, EventArgs e)
{
    // Sync up the trackbar with the value just entered in the spinbox
    myTrackBar.Value = Convert.ToInt32(myNumericUpDown.Value);
}

void myTrackBar_ValueChanged(object sender, EventArgs e)
{
    // Sync up the spinbox with the value just set on the trackbar
    myNumericUpDown.Value = myTrackBar.Value;
}

, , ( ), .

+8

Source: https://habr.com/ru/post/1784974/


All Articles