熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

一個拖動無標題欄窗體的方法

2022-06-13   來源: .NET編程 

  private bool isMouseDown = false;

  private Point FormLocation;     //form的location

  private Point mouseOffset;      //鼠標的按下位置

  private void Messages_MouseDown(object sender MouseEventArgs e)

  {

  try

  {

  if (eButton == MouseButtonsLeft)

  {

  isMouseDown = true;

  FormLocation = thisLocation;

  mouseOffset = ControlMousePosition;

  }

  }

  catch (Exception)

  {

  }

  }

  private void Messages_MouseMove(object sender MouseEventArgs e)

  {

  try

  {

  int _x = ;

  int _y = ;

  if (isMouseDown)

  {

  Point pt = ControlMousePosition;

  _x = mouseOffsetX ptX;

  _y = mouseOffsetY ptY;

  thisLocation = new Point(FormLocationX _x FormLocationY _y);

  }

  }

  catch (Exception )

  {

  }

  }

  private void Messages_MouseUp(object sender MouseEventArgs e)

  {

  try

  {

  isMouseDown = false;

  }

  catch (Exception)

  {


From:http://tw.wingwit.com/Article/program/net/201311/13175.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.