Control Study -> 实现:用鼠标拖动图片

本文介绍如何在ASP.NET WebForm中实现鼠标拖动图片的功能,通过按住鼠标左键拖动,图片会跟随鼠标移动。示例代码可供下载,并提供相关文章链接以供进一步学习。
摘要由CSDN通过智能技术生成

(一).说明

    功能:用鼠标实现拖动图片.
    用法:将鼠标指向一图片,按住鼠标左键拖动. 图片会随鼠标一起移动.

(二).图片显示效果

(三).代码

      说明:您可以将此功能用作其它用途,也可以用作设计其它的游戏.

  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
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值