(一).说明
功能:用鼠标实现拖动图片.
用法:将鼠标指向一图片,按住鼠标左键拖动. 图片会随鼠标一起移动.
(二).图片显示效果
(三).代码
说明:您可以将此功能用作其它用途,也可以用作设计其它的游戏.
1
using
System;
2 using System.Drawing;
3 using System.Collections;
4 using System.ComponentModel;
5 using System.Windows.Forms;
6 using System.Data;
7 using System.Threading;
8
9 namespace 拖动图片
10 {
11 /// <summary>
12 /// Form1 的摘要说明。
13 /// </summary>
14 public class Form1 : System.Windows.Forms.Form
15 {
16 public System.Windows.Forms.PictureBox[] pictureBox = new PictureBox[ 2 ];
17 // private System.Windows.Forms.PictureBox pictureBox2;
18 /// <summary>
19 /// 必需的设计器变量。
20 /// </summary>
21 private System.ComponentModel.Container components = null ;
22
23 public Form1()
24 {
25 //
26 // Windows 窗体设计器支持所必需的
27 //
28 InitializeComponent();
29 for ( int i = 0 ;i < 2 ;i ++ )
30 {
31 this .pictureBox[i].MouseUp += new System.Windows.Forms.MouseEventHandler( this .pictureBox1_MouseUp);
32 this .pictureBox[i].MouseMove += new System.Windows.Forms.MouseEventHandler( this .pictureBox1_MouseMove);
33 this .pictureBox[i].MouseDown += new
2 using System.Drawing;
3 using System.Collections;
4 using System.ComponentModel;
5 using System.Windows.Forms;
6 using System.Data;
7 using System.Threading;
8
9 namespace 拖动图片
10 {
11 /// <summary>
12 /// Form1 的摘要说明。
13 /// </summary>
14 public class Form1 : System.Windows.Forms.Form
15 {
16 public System.Windows.Forms.PictureBox[] pictureBox = new PictureBox[ 2 ];
17 // private System.Windows.Forms.PictureBox pictureBox2;
18 /// <summary>
19 /// 必需的设计器变量。
20 /// </summary>
21 private System.ComponentModel.Container components = null ;
22
23 public Form1()
24 {
25 //
26 // Windows 窗体设计器支持所必需的
27 //
28 InitializeComponent();
29 for ( int i = 0 ;i < 2 ;i ++ )
30 {
31 this .pictureBox[i].MouseUp += new System.Windows.Forms.MouseEventHandler( this .pictureBox1_MouseUp);
32 this .pictureBox[i].MouseMove += new System.Windows.Forms.MouseEventHandler( this .pictureBox1_MouseMove);
33 this .pictureBox[i].MouseDown += new