我写了一个无标题的窗体已经可以拖动了,
但是怎样才能通过拖拽来改变无标题窗体的大小。

解决方案 »

  1.   

    http://www.microsoft.com/china/community/Column/60.mspx
      

  2.   

    就三个事件.
    bord用于记录是那个边被选中.
     private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (beginsiae)
                {
                   
                     if((bord&1)!=0)
                  
                            if ((this.Height + currentY - MousePosition.Y) > 20)
                            {
                                this.Height = this.Height + currentY - MousePosition.Y;
                                this.Top = this.Top + MousePosition.Y - currentY;
                               
                            }
                   
                            
                      if((bord&2)!=0)
                         if ((this.Width + MousePosition.X - currentX) > 20)
                           this.Width = this.Width + MousePosition.X - currentX;
                                          if((bord&4)!=0)
                         if ((this.Height + MousePosition.Y - currentY) > 20)
                            this.Height = this.Height + MousePosition.Y - currentY;
                               
                    if((bord&8)!=0)
                        if ((this.Width + currentX - MousePosition.X) > 20)
                        {
                            this.Width = this.Width + currentX - MousePosition.X;
                            this.Left=this.Left+MousePosition.X-currentX;                    }
                          
                    currentX=MousePosition.X;
                    currentY=MousePosition.Y;            }
                else
                {
                    if (Math.Abs(this.Location.X - MousePosition.X) < 10)
                        bord = bord | 8;
                    else
                        bord = bord & 7;                if (Math.Abs(this.Location.X + this.Width - MousePosition.X) < 10)
                        bord = bord | 2;
                    else
                        bord = bord & 13;                if (Math.Abs(this.Location.Y - MousePosition.Y) < 10)
                        bord = bord | 1;
                    else
                        bord = bord & 14;                if (Math.Abs(this.Location.Y + this.Height - MousePosition.Y) < 10)
                        bord = bord | 4;
                    else
                        bord = bord & 11;
                    switch (bord)
                    {
                        case 1:
                        case 4:
                            this.Cursor = Cursors.SizeNS;
                            break;
                        case 2:
                        case 8:
                            this.Cursor = Cursors.SizeWE;
                            break;
                        case 3:
                        case 12:
                            this.Cursor = Cursors.SizeNESW;
                            break;
                        case 9:
                        case 6:
                            this.Cursor = Cursors.SizeNWSE;
                            break;
                        default:
                            this.Cursor = Cursors.Default;
                            break;
                    }
                }        }        int currentX = 0;
            int currentY = 0;
            bool beginsiae = false;
            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                if (bord==0)
                    return;
                else
                {
                    currentX = MousePosition.X;
                    currentY = MousePosition.Y;
                    beginsiae = true;
                }        }        private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                beginsiae = false;
                bord = 0;
                currentX = 0;
                currentY = 0;
            }