打开在特定时间后选择的任何文件
本文关键字:选择 任何 文件 定时间 | 更新日期: 2023-09-27 17:59:09
我希望我的程序在指定时间后打开filedialo1选择的选定文件,请回答任何问题
这是我的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
string Chosen_File = " ";
}
public void timer1_Tick(object sender, EventArgs e)
{
string Chosen_File = openFileDialog1.FileName;
Process.Start(Chosen_File);
timer1.Enabled = true;
}
}
}
错误是系统找不到指定的文件
如果您想通过电子邮件将答案发送给您,您可以勾选问题下方的框。
问题是您没有保存文件名。
我最初也会禁用计时器,以防止用户取消对话框时它试图打开文件。此外,不要忘记在其tick
事件处理程序中禁用计时器,否则该文件将被多次打开。
string Chosen_File = null;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Chosen_File = MyDialog.FileName;
timer1.Enabled = true;
}