using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
    
public class Form1 : System.Windows.Forms.Form
    
{
        
private Point mouseOffset;
        
private bool isMouseDown = false;

        
private System.Windows.Forms.Button button1;
        
private System.ComponentModel.Container components = null;

        
public Form1()
        
{
            InitializeComponent();

        }


        
protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if (components != null
                
{
                    components.Dispose();
                }

            }

            
base.Dispose( disposing );
        }


        
Windows 窗体设计器生成的代码

        [STAThread]
        
static void Main() 
        
{
            Application.Run(
new Form1());
        }


        
private void button1_Click(object sender, System.EventArgs e) {
            
this.Close();
        }


        
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
            
int xOffset;
            
int yOffset;
            
//先记得窗体内部的作标,标以负数是因为:当前的Location=当前屏幕的光标位置+(-1*窗体内部作标)
            xOffset = -e.X;
            yOffset 
= -e.Y;

            mouseOffset 
= new Point(xOffset, yOffset);
            isMouseDown 
= true;

        }


        
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
            
if (isMouseDown) {
                Point mousePos 
= Control.MousePosition;
                
//移动后,用新的屏幕作标+(-1*窗体内部作标)=窗体的Location+增量N,而增量N对于三个数来讲都是相对的,
                
//所以Form的新作标为原Location+增量N.
                mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                Location 
= mousePos;
            }


        }


        
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {

            
if (e.Button == MouseButtons.Left) {
         &nb#
posted on 2006-09-27 14:23 毁于随 阅读(93) 评论(1)  编辑 收藏 所属分类: C# 编程经验

  回复  引用    
2007-05-30 02:57 | Yuki [未注册用户]
怎么都没写完呢

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2006-09-28 09:43 编辑过


相关链接: