How to create a custom MessageBox?

后端 未结 4 1209
星月不相逢
星月不相逢 2020-11-27 06:09

I\'m trying to make a custom message box with my controls.

public static partial class Msg : Form
{
    public static void show(string content, string descri         


        
4条回答
  •  时光取名叫无心
    2020-11-27 07:02

    In a WPF project you can add a new window and call it MessageBoxCustom then inside C# the Void where you can find InitialiseComponent(); you add 2 properties and bind those properties to the textBlocks you should have created inside your XAML view Example:

    public MessageBoxCustom(string Message, string Title)
    {
        InitialiseComponent();//this comes first to load Front End
        textblock1.Text = Title;
        textblock2.Text = Message;
    }
    
    Just position your TextBlocks where you want them to be displayed in XAML
    
    
    From your Main Window you can call that message box like this
    
    
    private void Button_Click()
    {
        MessageBoxCustom msg = new MessageBoxCustom("Your message here","Your title her");
        msg.ShowDialog();
    }
    

提交回复
热议问题