In your form, Deactivate the event, put "this.Close ()". Your form will be closed as soon as you click elsewhere on Windows.
Update. I think that now you have the Volume button, and inside the Click event you create an instance of the VolumeSlider form and display it by calling ShowDialog (), which blocks until the user closes the pop-up form. In the next line, you read the volume that you selected user, and use it in your program.
This is normal, but as you noticed, it forces the user to explicitly close the pop-up window in order to return to the main program. Show () is the method that you really want to use here in your popup form, but Show () does not block, which means that the Click event on your main form ends without knowing what the new volume should be.
A simple solution is to create a public method in your main form as follows:
public void SetVolume(int volume) {
Then in your "Click" button (also in the main form) you will create a VolumeSlider as follows:
VolumeSlider slider = new VolumeSlider(); slider.Show(this); // the "this" is needed for the next step
In the VolumeSlider form, since the user is working with a scrollbar (I assume), you put this code in the ValueChanged event with a scrollbar (I think it is):
MainForm owner = (MainForm)this.Owner; owner.SetVolume(scrollbar.Value);
And then in the VolumeSlider form, deactivate the event that you would put this.Close (), as mentioned above. Your form will behave as expected.
source share