Class
-
Hi.I'm new in c#. Can anyone tell me hoe to convert this coding to a class? #region dragDrop panel3 private bool isDragging3=false; public int x3,y3; private void panel3_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e) { isDragging3 = true; x3 = e.X; y3 = e.Y; } private void panel3_MouseUp(System.Object sender, System.Windows.Forms.MouseEventArgs e) { isDragging3 = false; } private void panel3_MouseMove(System.Object sender, System.Windows.Forms.MouseEventArgs e) { if (isDragging3 == true) { panel3.Left = e.X + panel3.Left - x3; panel3.Top = e.Y + panel3.Top - y3; } } #endregion
-
Hi.I'm new in c#. Can anyone tell me hoe to convert this coding to a class? #region dragDrop panel3 private bool isDragging3=false; public int x3,y3; private void panel3_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e) { isDragging3 = true; x3 = e.X; y3 = e.Y; } private void panel3_MouseUp(System.Object sender, System.Windows.Forms.MouseEventArgs e) { isDragging3 = false; } private void panel3_MouseMove(System.Object sender, System.Windows.Forms.MouseEventArgs e) { if (isDragging3 == true) { panel3.Left = e.X + panel3.Left - x3; panel3.Top = e.Y + panel3.Top - y3; } } #endregion
One way to do this would be to derive a class from Panel and overload the OnMouseDown, OnMouseUp and OnMouseMove methods. class myPanel : Panel { ... protect override void OnMouseDown(MouseEventArgs e) { isDragging3 = true; x3 = e.X; y3 = e.Y; } ... } Mike
Started out with nothing and still have most of it left!
-
Hi.I'm new in c#. Can anyone tell me hoe to convert this coding to a class? #region dragDrop panel3 private bool isDragging3=false; public int x3,y3; private void panel3_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e) { isDragging3 = true; x3 = e.X; y3 = e.Y; } private void panel3_MouseUp(System.Object sender, System.Windows.Forms.MouseEventArgs e) { isDragging3 = false; } private void panel3_MouseMove(System.Object sender, System.Windows.Forms.MouseEventArgs e) { if (isDragging3 == true) { panel3.Left = e.X + panel3.Left - x3; panel3.Top = e.Y + panel3.Top - y3; } } #endregion
-
One way to do this would be to derive a class from Panel and overload the OnMouseDown, OnMouseUp and OnMouseMove methods. class myPanel : Panel { ... protect override void OnMouseDown(MouseEventArgs e) { isDragging3 = true; x3 = e.X; y3 = e.Y; } ... } Mike
Started out with nothing and still have most of it left!
thank for the solution. It's very helpful
-
One way to do this would be to derive a class from Panel and overload the OnMouseDown, OnMouseUp and OnMouseMove methods. class myPanel : Panel { ... protect override void OnMouseDown(MouseEventArgs e) { isDragging3 = true; x3 = e.X; y3 = e.Y; } ... } Mike
Started out with nothing and still have most of it left!
There are error to compile this code because panel3.left is not defined in the class. How to overcome this? if (isDragging3 == true) { panel3.Left = e.X + panel3.Left - x3; panel3.Top = e.Y + panel3.Top - y3; }
-
There are error to compile this code because panel3.left is not defined in the class. How to overcome this? if (isDragging3 == true) { panel3.Left = e.X + panel3.Left - x3; panel3.Top = e.Y + panel3.Top - y3; }
Most likely
panel3
IS the class (i.e.this
)
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
There are error to compile this code because panel3.left is not defined in the class. How to overcome this? if (isDragging3 == true) { panel3.Left = e.X + panel3.Left - x3; panel3.Top = e.Y + panel3.Top - y3; }
Sorry I cut and paste in a hurry as Mr. MacKay has suggested the proper syntax is; if (isDragging3 == true) { this.Left = e.X + this.Left - x3; this.Top = e.Y + this.Top - y3; } Hope this helps. Mike
Started out with nothing and still have most of it left!
-
Sorry I cut and paste in a hurry as Mr. MacKay has suggested the proper syntax is; if (isDragging3 == true) { this.Left = e.X + this.Left - x3; this.Top = e.Y + this.Top - y3; } Hope this helps. Mike
Started out with nothing and still have most of it left!
Thanks. This really works...