zoukankan      html  css  js  c++  java
  • 【WPF】对话框/消息弹窗

    非模式对话框

    需求:弹窗是非模式对话框,即可以多个弹窗弹出,且弹窗后面的窗体可以被操作,不会被锁定。

    自定义的窗体Window实现以下步骤:

    1. 在C#代码中弹出窗体时,使用 window.Show() 而不是 window.ShowDialog();
    2. 最好设置 window.Topmost = true; 可以在XAML顶部写、也可以在C#代码中设置。否则该窗体可以被主界面遮挡(比如按Tab切换到主界面时),该弹窗没有被关闭,但又看不到。
    3. 如有需要,可以设置 ResizeMode=”NoResize”; 可以在XAML顶部写、也可以在C#代码中设置。这样该弹窗将无法改变宽高,且没有最大化、最小化按钮。

    对话框、消息弹窗

    复制代码
    //定义消息框             
    string messageBoxText = "需要保存吗?";
    string caption = "HELLO";
    MessageBoxButton button = MessageBoxButton.YesNoCancel;
    MessageBoxImage icon = MessageBoxImage.Warning;
    //显示消息框              
    MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
    //处理消息框信息              
    switch (result)
    {
        case MessageBoxResult.Yes:
            // ...                      
            break;
        case MessageBoxResult.No:
            // ...                      
            break;
        case MessageBoxResult.Cancel:
            // ...                     
            break;
    }  
    复制代码

    简化的写法:

    复制代码
    MessageBoxResult result = MessageBox.Show("这里是消息内容", "这是标题", MessageBoxButton.YesNo);
    if (result == MessageBoxResult.Yes)
    {
        // do something
    }
    else
    {
        // do something
    }
    复制代码

    打开文件对话框

    复制代码
    //打开文件对话框              
    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<bool> result = dlg.ShowDialog();                
    // Process open file dialog box results              
    if (result == true)              
    {                  
        // Open document                  
        string filename = dlg.FileName;                    
        //...             
    }  
    复制代码

     

    转自:https://www.cnblogs.com/guxin/p/wpf-message-dialog.html

  • 相关阅读:
    springMVC+MyBatis+Spring+maven 整合(1)
    mysql.zip免安装版配置
    5.6 循环依赖
    5.5 准备创建bean
    5.4 获取单例
    SQL Server(九)——事务
    SQL Server(七)——存储过程
    SQL Server(八)——触发器
    SQL Server(六)——索引、视图和SQL编程
    SQL Server(五)——常用函数 转
  • 原文地址:https://www.cnblogs.com/javalinux/p/14484230.html
Copyright © 2011-2022 走看看