C# 按住鼠标左键 在picturebox之间拖动时picturebox显示效果的问题
我在panel里放了4*4的16个picturebox,现在要选择一个picturebox1,按住左键拖动,在鼠标移动到picturebox2时,picturebox2的...
我在panel里放了4*4的16个picturebox,现在要选择一个picturebox1,按住左键拖动,在鼠标移动到picturebox2时,picturebox2的图片变成半透明效果,移出picturebox2时,picturebox2的图片恢复原来效果
要实现这种效果,都需要什么事件,过程是怎样的,最好描述详细点,有部分实现代码
希望有心人解答 直接百度,复制粘贴的就算了
我用了picturebox的MouseEnter事件,但按住左键拖动时,事件不会触发 展开
要实现这种效果,都需要什么事件,过程是怎样的,最好描述详细点,有部分实现代码
希望有心人解答 直接百度,复制粘贴的就算了
我用了picturebox的MouseEnter事件,但按住左键拖动时,事件不会触发 展开
2013-08-30
展开全部
//以下是设置PictureBox移动的代码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 WindowsFormsApplication1
{
public partial class FrmPiceboxTd : Form
{
public FrmPiceboxTd()
{
InitializeComponent();
foreach (Control c in this.Controls)
{
if (c is PictureBox)
{
c.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pic_MouseMove);
c.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
}
}
}
private Point downPoint;//单击picturebox的坐标 private void pic_MouseDown(object sender, MouseEventArgs e)
{
//设置单击picturebox的坐标
if (e.Button == MouseButtons.Left)
{
downPoint = e.Location;
}
} private void pic_MouseMove(object sender, MouseEventArgs e)
{
//实现图片随鼠标拖动
if (e.Button == MouseButtons.Left)
{
((Control)sender).Location = new Point(
((Control)sender).Location.X + e.X - downPoint.X,
((Control)sender).Location.Y + e.Y - downPoint.Y);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class FrmPiceboxTd : Form
{
public FrmPiceboxTd()
{
InitializeComponent();
foreach (Control c in this.Controls)
{
if (c is PictureBox)
{
c.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pic_MouseMove);
c.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
}
}
}
private Point downPoint;//单击picturebox的坐标 private void pic_MouseDown(object sender, MouseEventArgs e)
{
//设置单击picturebox的坐标
if (e.Button == MouseButtons.Left)
{
downPoint = e.Location;
}
} private void pic_MouseMove(object sender, MouseEventArgs e)
{
//实现图片随鼠标拖动
if (e.Button == MouseButtons.Left)
{
((Control)sender).Location = new Point(
((Control)sender).Location.X + e.X - downPoint.X,
((Control)sender).Location.Y + e.Y - downPoint.Y);
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询