Cursor.Clip

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 10
Reputation: nlblnx is an unknown quantity at this point 
Solved Threads: 0
nlblnx nlblnx is offline Offline
Newbie Poster

Cursor.Clip

 
0
  #1
Jul 23rd, 2009
Hi all,

Does anyone have a good example of using Cursor.Clip?

I need to be able to restrict movement to a form only when the left mouse button is pressed, so using:

  1. if(e.Button == MouseButtons.Left){}

Any help would be appreciated.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,215
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 573
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Cursor.Clip

 
0
  #2
Jul 23rd, 2009
I'm off somewhere by a couple of pixels... but close enough:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace daniweb
  11. {
  12. public partial class frmPanel : Form
  13. {
  14. private Point start;
  15. private Rectangle origClip;
  16.  
  17. public frmPanel()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void panel1_MouseDown(object sender, MouseEventArgs e)
  23. {
  24. if (e.Button == MouseButtons.Left)
  25. {
  26. origClip = Cursor.Clip;
  27. start = e.Location;
  28. panel1.MouseUp += new MouseEventHandler(panel1_MouseUp);
  29. panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
  30.  
  31. Point topLeft = this.PointToScreen(new Point(0 + e.X, 0 + e.Y));
  32. Point rightBottom = this.PointToScreen(new Point(this.Width, this.Height));
  33. Size sz = new Size(rightBottom.X - topLeft.X - e.X, rightBottom.Y - topLeft.Y - e.Y);
  34. Cursor.Clip = new Rectangle(topLeft, sz);
  35. }
  36. }
  37.  
  38. void panel1_MouseUp(object sender, MouseEventArgs e)
  39. {
  40. Cursor.Clip = origClip;
  41. panel1.MouseMove -= new MouseEventHandler(panel1_MouseMove);
  42. panel1.MouseUp -= new MouseEventHandler(panel1_MouseUp);
  43. }
  44.  
  45. void panel1_MouseMove(object sender, MouseEventArgs e)
  46. {
  47. panel1.Location = new Point(panel1.Location.X - (start.X - e.X), panel1.Location.Y - (start.Y - e.Y));
  48. }
  49. }
  50. }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC