OK啦,http://expert.csdn.net/Expert/topic/2235/2235675.xml?temp=.2538721
请rouser(我是一棵秋天的树) 来领分

解决方案 »

  1.   

    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 int ox;
    private int oy;
    private Control control; 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 );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(130, 115);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(278, 65);
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
    this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
    this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_MouseDown);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
    this.ClientSize = new System.Drawing.Size(536, 350);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.button1});
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
    this.Name = "Form1";
    this.Text = "Form1";
    this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
    this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
    this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
    this.ResumeLayout(false); }
    #endregion [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(this.control == null)
    return; if(e.Button == MouseButtons.Left)
    {
    this.control.Width += (e.X - ox);
    this.control.Height += (e.Y - oy);
    }
    } private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    {
    ox = e.X;
    oy = e.Y;
    this.Capture = true;
    }
    } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    this.Capture = false;
    } private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    this.control = (Control)sender;
    if(e.X > (this.control.ClientSize.Width - 4))
    {
    this.Cursor = Cursors.SizeWE;
    if(e.Y > (this.control.ClientSize.Height - 4))
    this.Cursor = Cursors.SizeNWSE;
    }
    else if(e.Y > (this.control.ClientSize.Height - 4))
    this.Cursor = Cursors.SizeNS;
    else
    this.Cursor = Cursors.Default;
    } private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    this.control = null;
    }
    }
    }
      

  2.   

    調試完了,這段代碼是對的 :)using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Data;namespace WindowsApplication1
    {
    public class Form1 : System.Windows.Forms.Form
    {
    private int ox;
    private int oy;
    private Control control; 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 );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.BackColor = System.Drawing.SystemColors.ControlDark;
    this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.button1.Location = new System.Drawing.Point(130, 115);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(278, 104);
    this.button1.TabIndex = 0;
    this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
    this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
    this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_MouseDown);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
    this.ClientSize = new System.Drawing.Size(536, 350);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.button1});
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
    this.Name = "Form1";
    this.Text = "Form1";
    this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
    this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
    this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
    this.ResumeLayout(false); }
    #endregion [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(this.control == null)
    return; if(e.Button == MouseButtons.Left)
    {
    if(this.Cursor == Cursors.SizeWE)  // <---->
    {
    this.control.Width += (e.X - ox);
    //Debug.WriteLine(this.control.Width.ToString());
    ox = e.X;
    return;
    } if(this.Cursor == Cursors.SizeNS)
    {
    this.control.Height += (e.Y - oy);
    //Debug.WriteLine(this.control.Height.ToString());
    oy = e.Y;
    return;
    } if(this.Cursor == Cursors.SizeNWSE)
    {
    this.control.Width += (e.X - ox);
    this.control.Height += (e.Y - oy);
    //Debug.WriteLine(this.control.Width.ToString());
    //Debug.WriteLine(this.control.Height.ToString());
    ox = e.X;
    oy = e.Y;
    return;
    }
    }
    } private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    {
    ox = e.X + ((Control)sender).Left;
    oy = e.Y + ((Control)sender).Top;
    this.Capture = true;
    }
    } private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    this.control = (Control)sender;
    if(e.X > (this.control.ClientSize.Width - 4))
    {
    this.Cursor = Cursors.SizeWE;  // <---->
    if(e.Y > (this.control.ClientSize.Height - 4))
    this.Cursor = Cursors.SizeNWSE;
    }
    else if(e.Y > (this.control.ClientSize.Height - 4))
    this.Cursor = Cursors.SizeNS;
    else
    this.Cursor = Cursors.Default;
    } private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    this.control = null;
    } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    {
    this.Capture = false;
    this.Cursor = Cursors.Default;
    }
    }
    }
    }
      

  3.   

    我改了一下:
    private void Form3_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.X > (this.ClientSize.Width - 4))
    {
    this.Cursor = Cursors.SizeWE;
    if(e.Y > (this.ClientSize.Height - 4))
    {
    this.Cursor = Cursors.SizeNWSE;
    }
    }
    else if(e.Y > (this.ClientSize.Height - 4))
    {
    this.Cursor = Cursors.SizeNS;
    }
    else
    this.Cursor = Cursors.Default;
    } private void Form3_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    {
    ox = e.X;
    oy = e.Y;
    this.Capture = true;
    }
    } private void Form3_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(ox > (this.ClientSize.Width - 4))
    {
    this.Cursor = Cursors.SizeWE;    
    if(e.Button == MouseButtons.Left)
    this.Width += (e.X - ox);
    if(oy > (this.ClientSize.Height - 4))
    {
    this.Cursor = Cursors.SizeNWSE;  
    if(e.Button == MouseButtons.Left)
    this.Height += (e.Y - oy);
    }
    }
    else if(oy > (this.ClientSize.Height - 4))
    {
    this.Cursor = Cursors.SizeNS;  
    if(e.Button == MouseButtons.Left)
    this.Height += (e.Y - oy);
    }
    else
    this.Cursor = Cursors.Default;
    }