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


    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();      
                    }          
                }
            }      
        
        }
    }

  • 相关阅读:
    设计模式学习笔记建造者模式
    ajax应用总结
    带有角色信息的FormsAuthentication身份验证
    jquery.validate中文API和应用实例(一)简单验证
    jquery.validate中文API和应用实例(三)高级验证基础
    设计模式学习笔记抽象工厂模式
    jquery.validate中文API和应用实例(二)简单验证规则的应用
    扩展jquery实现客户端表格的分页、排序
    如何查看修改mysql编码格式
    emacs使用技巧
  • 原文地址:https://www.cnblogs.com/gaolijun1986/p/2114066.html
Copyright © 2020-2023  润新知