如何显示一个消息框,指示拖放类中的文件格式错误? [英] How to display a messagebox indicate wrong file format in drag-n-drop class?

查看:43
本文介绍了如何显示一个消息框,指示拖放类中的文件格式错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi..i每当将文本文件拖放到窗体中时,都使用拖放类对数据进行处理.但是,每当将文本文件以外的文件拖放到窗体中时,如何显示消息框以指示错误的文件格式?以下是我的程序的一些代码,我在某个地方和哪里应该加错吗?谢谢.

Hi..i use drag and drop class to undergo process of data whenever a text file is drag into the form..But how to display a messagebox indicate wrong file format whenever file other than text file is drag into the form?Below are some codes of my program,did i wrong somewhere and where should i add?thanks.

private void Form1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            string file= "";
            if(e.Data.GetDataPresent(DataFormats.Text))
            {
                file = (string)e.Data.GetData(DataFormats.Text);
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] fileNames;
                fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
                file = fileNames[0];
            }

推荐答案

MessageBox.Show("wrong file format");




如果正在拖动文件,您肯定可以检查文件扩展名,然后查看它是否为.txt?




If a file is being dragged on, surely you can check the file extension and see if it''s .txt ?


这篇关于如何显示一个消息框,指示拖放类中的文件格式错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆