您的位置:首页 > 其它

窗体中拖动panel,并且不会拖动至窗体外部程序实现方法。

2011-07-22 16:25 393 查看
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;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Point pt;
MouseEventHandler hand;
public Form1()
{
InitializeComponent();
}

private void panel1_MouseDown(object sender, MouseEventArgs e)
{
pt = Cursor.Position;
}

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y);
Cursor.Clip = new Rectangle(new Point(this.Location.X, this.Location .Y + 30), new Size(this.Width, this.Height - 30));
int px = Cursor.Position.X - pt.X;
int py = Cursor.Position.Y - pt.Y;
panel1.Location = new Point(panel1.Location.X + px, panel1.Location.Y + py);
pt = Cursor.Position;
}
}

private void Form1_Load(object sender, EventArgs e)
{
hand = new MouseEventHandler(panel1_MouseMove);
panel1.MouseMove += hand;
this.Cursor = Cursors.Default;
}

private void panel1_MouseUp(object sender, MouseEventArgs e)
{
Cursor.Clip = new Rectangle(new Point(0, 0), new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height));
System.Diagnostics.Process[] ss = System.Diagnostics.Process.GetProcesses();

foreach (System.Diagnostics.Process s in ss)
{
if (s.ProcessName.ToLower() == "test")
{
s.Kill();
}
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: