C# winform OpenFileDialog MessageBox

1.弹出窗体选择本地文件-OpenFileDialog

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "窗体左上角标题";//窗体左上角标题
openFileDialog.ShowHelp = true;//显示帮助按钮
openFileDialog.Filter = "文本文件(.txt)|*.txt|JPG文件(.jpg)|*.jpg|所有文件|*.*"; //过滤文件格式
//openFileDialog.Filter = "图片(.jpg .jpeg .gif)|*.jpg;*.jpeg;*.gif";//通过使用分号来分隔文件类型
openFileDialog.FilterIndex = 3;//格式索引 从1开始 1:文本文件 2:JPG文件 3:所有文件
openFileDialog.InitialDirectory = @"C:";//第一次打开的默认路径
openFileDialog.Multiselect = false;//文件是否能多选
//openFileDialog.DefaultExt = ".txt";//设置或获取文件扩展名

//选择好文件后点击OK按钮
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
    
}
效果图:

2.弹出窗体-提示警告-MessageBox 

if (true)
{
      DialogResult dr = MessageBox.Show("要提示的文本", "警告", MessageBoxButtons.OK);
      if (dr == DialogResult.OK)
      {
           return;
      }
}
效果图:
MessageBoxButtons指定若干常数,用以定义MessageBox上将显示哪些按钮(来自MSDN)
MessageBoxButtons成员
成员名称 说明
AbortRetryIgnore 消息框包含“中止”、“重试”和“忽略”按钮
OK 消息框包含“确定”按钮(默认)
OKCancel 消息框包含“确定”和“取消”按钮
RetryCancel 消息框包含“重试”和“取消”按钮
YesNo 消息框包含“是”和“否”按钮
YesNoCancel 消息框包含“是”、“否”和“取消”按钮

  

原文地址:https://www.cnblogs.com/zhyue93/p/WinForm_Popups.html