watching mouse cursor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • holestary
    New Member
    • Apr 2009
    • 5

    watching mouse cursor

    hi,

    i have to make an application in C#..that is form and there is an eye on it..while i moving the mouse cursor eye will watch it..but eye will not move with mouse cursor..it is only watching it simultaneously ...

    how can i do that.. i try it again and again but i couldn't do.. i asked that my friends..they say i should use mousemove event...and timer...but i couldn't..

    please help...
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Since you have tried several times... Show us what you have done so far and maybe someone can see where you are "close but not quite"

    Comment

    • holestary
      New Member
      • Apr 2009
      • 5

      #3
      Please use
      Code:
       ... your code here
      tags

      Code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Text;
      using System.Windows.Forms;
      
      namespace son
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }
      
      private void Form1_MouseMove(object sender, MouseEventArgs e)
      {
      {
      
      int x = e.X;
      
      int y = e.Y;
      
      groupBox1.Location = new Point(x, y);
      
      }
      }
      
      private void Form1_Load(object sender, EventArgs e)
      {
      
      }
      }
      }
      there is a picturebox on the groupbox...and while i moving the mouse groupbox move with it..but i want it only watch mouse cursor...
      Last edited by tlhintoq; Apr 18 '09, 02:04 AM. Reason: Please use [CODE] ... your code here [/CODE] tags

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        By "watch mouse cursor" do you mean you want eyes on the photo that move and appear to be following the cursor? Kind of like this

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          You need to get the location of the mouse.
          Get the location of the graphic
          Compare/get angle from one to the other
          Draw the eyes at the calculated angle.

          Comment

          • holestary
            New Member
            • Apr 2009
            • 5

            #6
            i tried to do something with pictures..but i couldn't..
            http://www.hscripts.com/scripts/Java...e-oncursor.php i found javascript what i want to do..i want this in C#..
            can i do that only one or two pics and codes???

            Code:
            using System;
            using System.Collections.Generic;
            using System.ComponentModel;
            using System.Data;
            using System.Drawing;
            using System.Text;
            using System.Windows.Forms;
            
            namespace mouse_takip
            {
                public partial class Form1 : Form
                {
                    public Form1()
                    {
                        InitializeComponent();
                    }
                        
                    private void Form1_MouseMove(object sender, MouseEventArgs e)
                    {
            
                        /*System.Drawing.Graphics formunyuzu = this.CreateGraphics();
                        int a= pictureBox1.Location.X;
                        int b = pictureBox1.Location.Y;
                        formunyuzu.TranslateTransform(a,b);   */
                        int X = Form1.MousePosition.X;
                        int Y = Form1.MousePosition.Y;
                        
                        if (X >= 0 && X < 12 ) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak1;
                        if (X >= 12 && X < 24) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak2;
                        if (X >= 24 && X < 36) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak3;
                        if (X >= 36 && X < 48) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak4;
                        if (X >= 48 && X < 60) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak5;
                        if (X >= 60 && X < 72) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak6;
                        if (X >= 72 && X < 84) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak7;
                        if (X >= 84 && X < 96) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak8;
                        if (X >= 96 && X < 108) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak9;
                        if (X >= 108 && X < 130) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak10;
                        if (X >= 130 && X < 142) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak11;
                        if (X >= 142 && X < 154) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak12;
                        if (X >= 154 && X < 166) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak13;
                        if (X >= 166 && X < 178) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak14;
                        if (X >= 178 && X < 190) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak15;
                        if (X >= 190 && X < 202) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak16;
                        if (X >= 202 && X < 214) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak17;
                        if (X >= 214 && X < 226) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak18;
                        if (X >= 226 && X < 238) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak19;
                        if (X >= 238 && X < 250) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak20;
                        if (X >= 250 && X < 262) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak21;
                        if (X >= 262 && X < 274) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak22;
                        if (X >= 274 && X < 286) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak23;
                        if (X >= 286 && X < 298) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak24;
                        if (X >= 298 && X < 310) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak25;
                        if (X >= 310 && X < 322) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak26;
                        if (X >= 322 && X < 334) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak27;
                        if (X >= 334 && X < 346) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak28;
                        if (X >= 346 && X < 360) pictureBox1.Image = mouse_takip.Properties.Resources.yuvarlak29;
                        
                 }
            
                    private void pictureBox1_MouseMove(object sender,System.Windows.Forms.MouseEventArgs e)
                    {
                    }
                }
            }

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              You need to get the location of the mouse.
              Get the location of the graphic
              Compare/get angle from one to the other
              Draw the eyes at the calculated angle.
              ... Or you could hard-code a brute force attack instead. Its your choice.

              Comment

              • holestary
                New Member
                • Apr 2009
                • 5

                #8
                thanks,
                i can get the location of the mouse but
                i dont know how can i get location of the graphic, calculate angle and draw the eyes at the angle..
                help me...i am beginner...

                Comment

                • tlhintoq
                  Recognized Expert Specialist
                  • Mar 2008
                  • 3532

                  #9
                  Drawing eyes.
                  Read up on the namespace "System.Drawing ". Simple eyes are nothing more than a white oval, with a colored circle inside it, with a black circle inside that.

                  Mouse coordinates are given relative to the screen. Your graphic location is relative to your form. So you need to convert it's location to its screen location so your are dealing with everything on the same terms.
                  Read up on the PointToScreen method.

                  As for the trigonometry to calculate the angles.
                  Here is a thread that covers it for someone else wanting to do the same thing (calculate the angle and distance of two points on the screen)

                  Amazing what you can find with Google.

                  Comment

                  Working...