.ShowDialog not creating modal form

861 Views Asked by At

Using C# .Net 4

My application loads an audio file at startup, in the event that the path to the audio file is invalid, we warn the user. I am making improvements which allows the user to locate the file, remove the association, or proceed unchanged.

Previously I was using the MessageBox to do this, and it worked great, however the need for custom buttons means that I had to create the custom dialog.

When I call this custom dialog it is not preventing actions on the main form, you can still click menus, buttons, drag and drop things, etc... Where the MessageBox does not allow interaction with the main form until you clicked OK or Cancel to dismiss the dialog. I have left both in the following method for demonstration.

So, calling the MessageBox.Show halts all actions to the main form, calling my custom form with .ShowDialog() does not, what am I doing wrong ?

private void PopulateWaveformAudio()
    {
        if (_sequence.GetAllMedia().Any())
        {
            IMediaModuleInstance media = _sequence.GetAllMedia().First();
            Audio audio = media as Audio;
            toolStripMenuItem_removeAudio.Enabled = true;
            if (audio.MediaExists)
            {
                TimelineControl.Audio = audio;
                toolStripButton_AssociateAudio.ToolTipText = string.Format("Associated Audio: {0}",
                    Path.GetFileName(audio.MediaFilePath));
            }
            else
            {
                InvalidAudioPathDialog result = new InvalidAudioPathDialog(audio.MediaFilePath);
                result.ShowDialog();

                switch(result.InvalidAudioDialogResult)
                {
                    case InvalidAudioDialogResult.KeepAudio:
                        break;
                    case InvalidAudioDialogResult.RemoveAudio:
                        break;
                    case InvalidAudioDialogResult.LocateAudio:
                        break;

                }

                string message = String.Format("Audio file not found on the path:\n\n {0}\n\nPlease Check your settings/path.",
                    audio.MediaFilePath);
                Logging.Warn(message);
                MessageBox.Show(message, @"Missing audio file",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }

        }

    }
0

There are 0 best solutions below