窗体中拖动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();
}
}
}
}
}
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();
}
}
}
}
}
相关文章推荐
- java 外部调用c程序(后缀为.exe--是可以运行的程序--不是本地方法的实现)
- C#实现软件监控外部程序运行状态的方法
- activity全屏实现沉浸式效果,并且单独触摸不会弹出虚拟按键的方法
- 代码实现从我的主窗体里打开另外一个应用程序,并且让该程序像自己的MDI子窗体那样在父窗体的范围内显示
- C#拖动自己的定义标题栏(panel)以及实现窗体拖动关闭和最小化
- PHP实现执行外部程序的方法详解
- 三种方法实现窗体的拖动
- WinForm程序启动时不显示主窗体的实现方法(转)
- C#调用执行外部程序的实现方法
- 三种方法实现Delphi无标题窗体的拖动
- Delphi调用一个外部程序时,如何把外部程序的窗体放在主程序窗体的Panel上?
- VB使用shell函数打开外部exe程序的实现方法
- C# WinForm程序启动时不显示主窗体的实现方法
- WinForm程序启动时不显示主窗体的实现方法
- 实现窗体拖动的两种方法
- WinForm程序启动时不显示主窗体的实现方法
- C#实现软件监控外部程序运行状态的方法
- WinForm程序启动时不显示主窗体的实现方法
- C#中实现鼠标拖动窗体的方法
- 点击窗体任意部分拖动窗体实现方法