Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在运行时将图像从文件夹拖动到窗体?_C#_Winforms - Fatal编程技术网

C# 如何在运行时将图像从文件夹拖动到窗体?

C# 如何在运行时将图像从文件夹拖动到窗体?,c#,winforms,C#,Winforms,目前我正在从按钮加载图像。但现在我必须在运行时将图像从文件夹拖动到图片框。我们如何实现这一点 好。下面的代码工作正常 private void pictureBox1_DragEnter(object sender, DragEventArgs e) { try { pictureBox1.Image = null; string[] filename = (string[])e.Data.GetData

目前我正在从按钮加载图像。但现在我必须在运行时将图像从文件夹拖动到图片框。我们如何实现这一点

好。下面的代码工作正常

 private void pictureBox1_DragEnter(object sender, DragEventArgs e)
    {

        try
        {
            pictureBox1.Image = null;
            string[] filename = (string[])e.Data.GetData(DataFormats.FileDrop);
            pictureBox1.Image = Image.FromFile(filename[0]);
        }
        catch (Exception expr)
        { }
    }
也许这些链接可以帮助您:,