Search code examples
c#wpfmessagebox

How to create message box in wpf


I am making an application where I need to use message box. I am trying to make my own custom message box in WPF. I am newbie to WPF. I have searched for it on google but not able to find proper solution. I find a way for it but not sure it will work or not.

I have added a another form which I want to use it as message box. In the main form, I have written:

MyMessageBox Box; 
public MainWindow()
{
    InitializeComponent();
    Box = new MyMessageBox();
}

private void button_Click(object sender, RoutedEventArgs e)
{
   Box.Show();
}

I have button in main window.So whenever I click on that button, message box window appears. I want to know that

1.is this the correct way of doing it.?

2.What additional code I have to add two made buttons of YES NO CANCEL according to requirement like in original windows messagebox

3.Please guide me to the tutorials where this process has already been covered.

Thanks


Solution

  • This is your simplest solution

            MessageBox.Show("This is your messagebox  with AbortRetryIgnore Buttons", "Your title", MessageBoxButtons.AbortRetryIgnore);
    
            MessageBox.Show("This is your messagebox with OK Button", "Your title", MessageBoxButtons.OK);
    
            MessageBox.Show("This is your messagebox with OK Cancel Buttons", "Your title", MessageBoxButtons.OKCancel);
    
    
            MessageBox.Show("This is your messagebox with Retry  Cancel Buttons", "Your title", MessageBoxButtons.RetryCancel);
    
    
            MessageBox.Show("This is your messagebox with Yes No Buttons", "Your title", MessageBoxButtons.YesNo);
    
            MessageBox.Show("This is your messagebox with Yes No Cancel Buttons", "Your title", MessageBoxButtons.YesNoCancel);