WPF message box

Pop modeless dialogs, which can eject a plurality of pop, pop, and the latter form can be operated without being locked.

Custom Window Forms implementation of the following steps:

C # code when the pop-up form, used window.Show () instead window.ShowDialog ();

Preferably provided window.Topmost = true; can be written at the top of XAML, may be provided in C # code. Otherwise, the form may be blocked main interface (such as Tab to the main screen), the window is not closed the missile, but can not see.

If necessary, may be provided ResizeMode = "NoResize"; the XAML can be written at the top, may be provided in C # code. Such that the change will not pop width and height, and not maximize, minimize button.

// define the message box

string messageBoxText = "need to save it?";

string caption = “HELLO”;

MessageBoxButton button = MessageBoxButton.YesNoCancel;

MessageBoxImage icon = MessageBoxImage.Warning;

// display a message box

MessageBoxResult result = MessageBox.Show(messageBoxText, caption,
button, icon);

// handle the message box information

switch (result)

{

case

MessageBoxResult.Yes:

    // ...                      

    break;

case

MessageBoxResult.No:

    // ...                      

    break;

case

MessageBoxResult.Cancel:

    // ...                     

    break;

}

// Open File dialog box

Microsoft.Win32.OpenFileDialog dlg = new
Microsoft.Win32.OpenFileDialog();

dlg.FileName = “Document”; // Default file name

dlg.DefaultExt = “.txt”; // Default file extension

dlg.Filter = “Text documents (.txt)|*.txt”; // Filter
files by extension

// Show open file dialog box

Nullable result = dlg.ShowDialog();

// Process open file dialog box results

if (result == true)

{

// Open document                  

string filename =

dlg.FileName;

//...             

}
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_44589117/article/details/94958769