티스토리 뷰

Application/C#

컨트롤 드래그

알 수 없는 사용자 2010. 10. 31. 00:18
   1: private Point 
   2: start_p; 
   3: // 클릭시 마우스 위치
   4: private Point 
   5: end_p; 
   6: // 마우스 이동할때 위치
   7: private bool mouse_move = false; // 마우스가 드레그 상태인지 
   8: 확인
   9: private void button2_MouseMove(object sender, MouseEventArgs e)
  10: // 마우스 
  11: 이동시
  12: {
  13:  Point th; // 마우스의 현재위치를 계산하기 위한 폼의 
  14: 위치
  15:  if (mouse_move == true)
  16:  
  17: {
  18:  th = 
  19: this.Location;
  20:  end_p = 
  21: ((Control)sender).PointToScreen(new Point(e.X, 
  22: e.Y));
  23:  Point tmp = new 
  24: Point((button2.Location.X + (end_p.X - start_p.X)), (button2.Location.Y + 
  25: (end_p.Y - start_p.Y)));
  26:  start_p = 
  27: ((Control)sender).PointToScreen(new Point(e.X, 
  28: e.Y));
  29:  
  30:  
  31:  button2.Location = 
  32: tmp;
  33:  }
  34: }
  35: private void button2_MouseDown(object sender, MouseEventArgs e)
  36: // 마우스로 
  37: 컨트롤 클릭시
  38: {
  39:  mouse_move = 
  40: true;
  41:  start_p = ((Control)sender).PointToScreen(new 
  42: Point(e.X, e.Y));
  43: }
  44: private void button2_MouseUp(object sender, MouseEventArgs e)
  45: // 컨트롤에서 마우스 
  46: 놓았을 때 
  47: {
  48:  mouse_move = false;
  49: }

'Application > C#' 카테고리의 다른 글

XNA를 시작합시다!  (0) 2011.12.31
Using Cleartype font in Windows Embedded CE  (0) 2010.11.02
C# 메세지 처리  (0) 2010.07.16
닷넷에서의 INI 파일 입출력  (0) 2010.07.15
C# Frequently Asked Questions for C++ programmers  (0) 2008.03.18