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 WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { //PictureBox MyX = new PictureBox(); //PictureBox MyY = new PictureBox(); InitializeComponent(); MyX.MouseDown +=new MouseEventHandler(MyX_MouseDown); MyX.MouseMove +=new MouseEventHandler(MyX_MouseMove); Point pX = new Point(230, 316); Point pY = new Point(20, 316); Bitmap X = new Bitmap("X.png"); Bitmap Y = new Bitmap("O.jpg"); MyX.BackgroundImage = X; MyX.BackgroundImageLayout = ImageLayout.Stretch; MyY.BackgroundImage = Y; MyY.BackgroundImageLayout = ImageLayout.Stretch; // int kolommen = 4; int rijen = 4; int aantalElementen = (kolommen * rijen) + 1; PictureBox[] Boxes = new PictureBox[aantalElementen]; int tellerIndex = 1; for (int tellerRij = 1; tellerRij <= rijen; tellerRij++) { for (int tellerKol = 1; tellerKol <= kolommen; tellerKol++) { Boxes[tellerIndex] = new PictureBox(); Boxes[tellerIndex].Name = "Picturebox" + tellerIndex.ToString(); Point positie = new Point((-50 + (tellerKol * 70)), (-50 + (tellerRij * 70))); Boxes[tellerIndex].Width = 60; Boxes[tellerIndex].BorderStyle = BorderStyle.FixedSingle; Boxes[tellerIndex].Height = 60; Boxes[tellerIndex].Location = positie; Boxes[tellerIndex].AllowDrop = true; tellerIndex++; } } MyX.BorderStyle = BorderStyle.Fixed3D; MyX.Height = 60; MyX.Width = 60; MyX.Image = X; MyX.SizeMode = PictureBoxSizeMode.StretchImage; MyY.BorderStyle = BorderStyle.Fixed3D; MyY.Height = 60; MyY.Width = 60; MyY.Image = Y; MyY.SizeMode = PictureBoxSizeMode.StretchImage; MyX.Location = pX; MyY.Location = pY; this.Controls.AddRange(Boxes); this.Controls.Add(MyX); this.Controls.Add(MyY); } bool isDragging = false; int CurrentX, CurrentY; private void MyX_MouseMove(object sender, MouseEventArgs e) { if (isDragging == true) { MyX.Top = MyX.Top + (e.Y - CurrentY); MyX.Left = MyX.Left + (e.X - CurrentX); } } private void MyX_MouseDown(object sender, MouseEventArgs e) { isDragging = true; CurrentX = e.X; CurrentY = e.Y; } } }
MouseUp
isDragging
true
MyX
MyY
MyO
PictureBox
BringToFront
MyX.BringToFront();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)