拖放背景颜色

Drag & Drop background color

我希望在将文件从桌面拖放到窗体时更改 MainForm 的背景。 Photo of form, where I want to change BG 这是拖放功能的代码。

 private void ThisForm_DragEnter(object sender, DragEventArgs e)
    {
        
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            e.Effect = DragDropEffects.All;
            
        }
        else
            e.Effect = DragDropEffects.None;
    }
    private void ThisForm_DragDrop(object sender, DragEventArgs e)
    {
        
        string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
        if (files != null && files.Length != 0)
        {
            if (Path.GetExtension(files[0]) == ".pdf")
            {
                TextBoxSelectPdf.Text = files[0];
            }
            else
            {
                MessageBox.Show("Galimas tik PDF formatas");
            }

        }

    }

我的问题 - 如何在拖放文件时更改背景颜色。

根据您最后的评论,您的表单的 BackgroundColour 属性 似乎有问题。

您可以随时使用以下方法设置表单的背景颜色:

this.Backcolor = Color.Red;

只要在“颜色”后键入一个点,您就会看到一个下拉菜单,建议可用的颜色(可能仅适用于 Visual Studio)。然后,您可以设置所需的颜色。

即使您没有看到下拉菜单,红色、蓝色、黑色、白色等颜色也始终可用。

不要离开这部分! :)

如果您想在拖入某些内容时更改 BackgroundColour,请在 DragEnter 事件中在此 e.Effect = DragDropEffects.None; 之后的新行中添加上述行。