Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Class

Class

Scheduled Pinned Locked Moved C#
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shamsteady
    wrote on last edited by
    #1

    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

    G Mike HankeyM 2 Replies Last reply
    0
    • S shamsteady

      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

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      To make a class of that code, you just put the code in a class, but what is it that you wish to accomplish by doing so?

      --- single minded; short sighted; long gone;

      1 Reply Last reply
      0
      • S shamsteady

        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

        Mike HankeyM Offline
        Mike HankeyM Offline
        Mike Hankey
        wrote on last edited by
        #3

        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!

        S 2 Replies Last reply
        0
        • Mike HankeyM Mike Hankey

          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!

          S Offline
          S Offline
          shamsteady
          wrote on last edited by
          #4

          thank for the solution. It's very helpful

          1 Reply Last reply
          0
          • Mike HankeyM Mike Hankey

            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!

            S Offline
            S Offline
            shamsteady
            wrote on last edited by
            #5

            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; }

            C Mike HankeyM 2 Replies Last reply
            0
            • S shamsteady

              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; }

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • S shamsteady

                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; }

                Mike HankeyM Offline
                Mike HankeyM Offline
                Mike Hankey
                wrote on last edited by
                #7

                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!

                S 1 Reply Last reply
                0
                • Mike HankeyM Mike Hankey

                  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!

                  S Offline
                  S Offline
                  shamsteady
                  wrote on last edited by
                  #8

                  Thanks. This really works...

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups