怎么实现用鼠标拖动PictuerBox,我需要C#实现的

来源:百度知道 编辑:UC知道 时间:2024/09/22 15:34:16
就是用鼠标拖动PictuerBox,用C#实现的,如果好的话可以加分!

这个实现,非常简单。利用Windows的API

全部的源码,我都发布了,你可以去下载,地址我PM你了,这里不让发链接

public Form1()
{
InitializeComponent();
}

private Point offset;

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (MouseButtons.Left != e.Button)
return;
offset = this.PointToScreen(e.Location);
}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (MouseButtons.Left != e.Button)
return;
Point cur = MousePosition;
this.pictureBox1.Location = new Point(cur.X - offset.X, cur.Y - offset.Y);
}

仅供参考

using System;
using System.Drawing;
using System.Windows.Forms;

class Program
{
static void Main(string[] args)
{
Applicat