forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapePointToClient.cs
62 lines (60 loc) · 1.87 KB
/
ShapePointToClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace VbPowerPacksShapePointToClientCS
{
public partial class ShapePointToClient : Form
{
public ShapePointToClient()
{
InitializeComponent();
}
// <Snippet1>
private void Form1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
// Determine whether the drop is within the rectangle.
if (rectangleShape1.HitTest(e.X, e.Y)==true)
// Handle file data.
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
// Assign the file names to a string array, in
// case the user has selected multiple files.
{
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
try
{
// Assign the first image to the BackGroundImage
// property.
rectangleShape1.BackgroundImage = Image.FromFile(files[0]);
// Set the rectangle location relative to the form.
rectangleShape1.Location =
rectangleShape1.PointToClient(new Point(e.X, e.Y));
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
// If the data is a file, display the copy cursor.
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
// </Snippet1>
}
}