标签:并保存 dialog ati move gen 后缀 添加 zh-cn agent
在 DragDrop 生成的方法中添加代码如下:
private void Form1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } }
在 DragEnter 方法中添加代码如下:
private void Form1_DragEnter(object sender, DragEventArgs e) { //判断 string[] files = e.Data.GetData(DataFormats.FileDrop) as string[]; string file = files[0]; if (!file.ToLower().EndsWith(".png") && !file.ToLower().EndsWith(".jpg")) { MessageBox.Show("需要图片文件!"); return; } //PictureBox控件显示图片 Image.Load(file); }
private void button1_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { //PictureBox控件显示图片 Image.Load(openFileDialog.FileName); } }
private void button1_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { //PictureBox控件显示图片 Image.Load(openFileDialog.FileName); //获取用户选择文件的后缀名 string extension = Path.GetExtension(openFileDialog.FileName); //声明允许的后缀名 string[] str = new string[] { ".gif", ".jpge", ".jpg", ".png" }; if (!str.Contains(extension)) { MessageBox.Show("仅能上传gif,jpge,jpg格式的图片!"); } else { //获取用户选择的文件,并判断文件大小不能超过20K,fileInfo.Length是以字节为单位的 FileInfo fileInfo = new FileInfo(openFileDialog.FileName); if (fileInfo.Length > 20480) { MessageBox.Show("上传的图片不能大于20K"); } else { //绝对路径 string image = openFileDialog.FileName; // 是指XXX.jpg string picpath = openFileDialog.SafeFileName; File.Copy(openFileDialog.FileName, Application.StartupPath + "\\Image\\" + picpath); } } } }
标签:并保存 dialog ati move gen 后缀 添加 zh-cn agent
原文地址:http://www.cnblogs.com/miskis/p/7607024.html