c# 选择文件或文件夹

时间: 2022-02-07 / 分类: C# / 浏览次数: 305 views / 0个评论 发表评论
		void Button1_select_ffmpegClick(object sender, EventArgs e)
		{
			 //选择文件
			OpenFileDialog dialog = new OpenFileDialog();
			dialog.Multiselect = true;//该值确定是否可以选择多个文件
			dialog.Title = "请选择文件夹";
			dialog.Filter = "所有文件(*.*)|*.*";
			if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				ffmpeg_address.Text = dialog.FileName;//把值保存到文本框
			}			
		}
		void Button1_select_dirClick(object sender, EventArgs e)
		{
			FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";
            dialog.SelectedPath = "E:\\新建文件夹";//默认文件夹
            //dialog.RootFolder = Environment.SpecialFolder.Programs;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                textBox1_editdir.Text = dialog.SelectedPath;//把值保存到文本框
			}
		}

发表评论

您的昵称 *

您的邮箱 *

您的网站