我添加了一个OpenFileDialog
按钮(称为“浏览”)按下事件,它应该打开一个对话框,获取文件名并将其返回给我。
using System;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string lastFileOpenPath = "";
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Please choose the file";
ofd.InitialDirectory = (Directory.Exists(lastFileOpenPath) ? lastFileOpenPath : @"C:\");
string archiveExt = "";
for (int cn = 1; cn <= 50; cn++)
archiveExt += (archiveExt == "" ? "" : ";") + "*." + cn.ToString().PadLeft(3, '0');
ofd.Filter = "Archive File (*.rar)|*.rar|Archive Files (*.###)|" + archiveExt + "|All Supported Files (*.rar, *.###)|" + archiveExt + ";*.rar";
ofd.FilterIndex = 3;
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() == DialogResult.OK && File.Exists(ofd.FileName))
{
FilePath.Text = ofd.FileName;
lastFileOpenPath = Path.GetDirectoryName(FilePath.Text);
}
}
}
}
}
出于某种原因,每当我按下Browse
按钮(即使我什么都不做并点击取消)然后尝试关闭打开的表单时,我都会在Output
窗口中收到以下消息。如果我打开表单,然后关闭它,则不会出现该消息。如果我打开表单,单击浏览按钮,点击取消然后关闭表单,它确实会出现。
断言失败:尚未执行成功的 WSASTARTUP (........\src\signaler.cpp:194)
是否有可能解决这个问题,所以“错误”(如果是错误)不会出现在Output
窗口中?我不是在问,因为这很烦人,我可以不在乎调试输出窗口中的消息。我问是因为优化。