如何根据鼠标光标移动画成圆形的眼睛? [英] How to move the eyes drawn in a circle according to the mouse cursor ?

查看:105
本文介绍了如何根据鼠标光标移动画成圆形的眼睛?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作Google Eyes(卡通),并使他的眼睛根据鼠标光标移动,就像光标移到哪里一样,眼睛也应该随之移动.

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.

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)
      {

      }
    }
}

推荐答案

所示的代码只有一个问题:它是由非程序员编写的,他可能甚至不想成为一个程序员.即使是一个非常糟糕的程序员,也永远不会写下几乎相同的29行代码.您根本无法获得编程的目的.一切都与抽象有关.

现在,您似乎已经为一个小组分配了相同的学校作业(请参见下文).如果是这样,那是一所什么样的学校?

无论如何,我在CodeProject上看到了相同的问题,并进行了详细回答,请参见:
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


这篇关于如何根据鼠标光标移动画成圆形的眼睛?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆