简体   繁体   中英

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

based on your example: You have to defiened your own window MyMessageBox of Window .

What you are looking for is MessageBox.Show() with all overloads.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM