Click here to Skip to main content
15,886,782 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make Google Eyes (cartoon) and to make his eyes moved according to mouse cursor , like wherever the cursor goes the eyes should move with that.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Eyes
{
    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 = Eyes.Properties.Resources;
            if (X >= 12 && X < 24) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak2;
            if (X >= 24 && X < 36) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak3;
            if (X >= 36 && X < 48) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak4;
            if (X >= 48 && X < 60) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak5;
            if (X >= 60 && X < 72) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak6;
            if (X >= 72 && X < 84) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak7;
            if (X >= 84 && X < 96) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak8;
            if (X >= 96 && X < 108) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak9;
            if (X >= 108 && X < 130) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak10;
            if (X >= 130 && X < 142) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak11;
            if (X >= 142 && X < 154) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak12;
            if (X >= 154 && X < 166) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak13;
            if (X >= 166 && X < 178) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak14;
            if (X >= 178 && X < 190) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak15;
            if (X >= 190 && X < 202) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak16;
            if (X >= 202 && X < 214) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak17;
            if (X >= 214 && X < 226) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak18;
            if (X >= 226 && X < 238) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak19;
            if (X >= 238 && X < 250) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak20;
            if (X >= 250 && X < 262) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak21;
            if (X >= 262 && X < 274) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak22;
            if (X >= 274 && X < 286) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak23;
            if (X >= 286 && X < 298) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak24;
            if (X >= 298 && X < 310) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak25;
            if (X >= 310 && X < 322) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak26;
            if (X >= 322 && X < 334) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak27;
            if (X >= 334 && X < 346) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak28;
            if (X >= 346 && X < 360) pictureBox1.Image = Eyes.Properties.Resources.yuvarlak29;

        }

      private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
      {
      }

      private void pictureBox1_Click(object sender, EventArgs e)
      {

      }

      private void Form1_Load(object sender, EventArgs e)
      {

      }
    }
}
Posted
Updated 21-Dec-11 5:40am
v3
Comments
Tim Groven 21-Dec-11 10:16am    
What have you tried so far? Where is your problem at?
Sergey Alexandrovich Kryukov 21-Dec-11 12:34pm    
Sorry, I had to remove the comment OP put in reply to your question. It was a code dump (which makes no sense). Mehdi put in in the body of the question, see above -- or better don't, because there is nothing to see...
--SA
fjdiewornncalwe 21-Dec-11 13:12pm    
Actually there is way to much to see. It's quite painful, in fact.
Mehdi Gholam 21-Dec-11 10:33am    
EDIT -> moved code in comment to the question
zahra1991 21-Dec-11 10:46am    
kindly tell me how to do it plz

1 solution

The code shown has only one problem: it is written by a non-programmer who is probably not even trying to became one. Even a very bad programmer will never write down 29 lines of code which are nearly identical. You are simply not getting what is programming for. It is all about abstraction.

Now, it looks like you have identical school assignment for a group (see below). If this is so, what kind of school is that?

Anyway, I saw an identical questions here at CodeProject and answered in detail, please see: How to make the eyes move according to the cursor of the mouse?[^].

You need a radical change in how you approach to learning programming or maybe a different kind of career. Maybe your school does not help you, but the attempt shown in this post is not good enough even if you had no school. Sorry for not very encouraging words, but I really would like to help you.

—SA
 
Share this answer
 
Comments
zahra1991 21-Dec-11 12:58pm    
Thanx alot yeah i confess that am not very good in programming but i really to be a gud programmer , but tell what would you do if your teacher asks you to make a program , such program about which you dont have any idea .. infact you dont know the logics about that ?
fjdiewornncalwe 21-Dec-11 13:15pm    
Your instructor is trying to make you think for yourselves. A good programmer is not necessarily the most skilled at writing cool looking and clean executing code, but rather is good at breaking down big problems into smaller, manageable ones and then finding solutions to those small problems that will work together to solve the bigger one.
zahra1991 21-Dec-11 13:18pm    
yeah u are right have made some changes but the black eye balls are not moving plz have alook what should i do ?
fjdiewornncalwe 21-Dec-11 13:13pm    
+5. harsh, but true.
Sergey Alexandrovich Kryukov 21-Dec-11 13:21pm    
Thank you, Marcus. I could talk in a smooth way, but would it be useful? In some critical situations surgery helps a bit better then conservative medicine. Of course I'm afraid the most to be wrong; and I would rather be happy to appear wrong, in this case...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900