我被困在这里。我想在“看”光标(角度)时画出眼睛。此外,它应该包含在更大的圆圈/象限内(就像眼球一样)。可悲的是,它不会在正确的位置/角度和每次鼠标移动时吸引我的眼球。它唯一会做的就是最初在 (0,0) 处绘制一个椭圆,但这不是我想要的。
我的想法是用勾股定理计算三角形的比率。然后在方法中应用正确的坐标(具有正确的比例)drawEllipse();
。每次移动光标时都应重复此操作。
您可以检查我的图像以了解数学推理。
这是我的代码,请注意面板是在此代码中未包含的设计器模式下制作的,但应该没什么大不了的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace oogjes2
{
public partial class Form1 : Form
{
public int mousex;
public int mousey;
public Form1()
{
InitializeComponent();
panel1.Paint += paintpanel;
panel1.MouseMove += panel1_MouseMove;
}
//panel1 cover the screen from (0.0) and onwards,
void panel1_MouseMove(object sender, MouseEventArgs mea)
{
int mousex = mea.X;
int mousey = mea.Y;
}
void paintpanel(object obj, PaintEventArgs pea)
{
Pen blackpen = new Pen(Color.Black, 3);
// the black outer circle which doesnt move
pea.Graphics.DrawEllipse(blackpen, -125, -125, 250, 250);
// e = 63. Diagonal distance from (0,0) to starting point drawEllipse
// factor = multiplication from mea.x and mea.y to the respective ex and ey of the small circle.
// ey = factor * mousex (mea.X). Same for ex.
float e = (float)Math.Sqrt(45 * 45 + 45 * 45); //=63
float factor = (e / (float)Math.Sqrt(mousex * mousex + mousey * mousey));
int ex = mousex * (int)factor;
int ey = mousey * (int)factor;
// the eye that should be redrawn at every mousemovement
pea.Graphics.DrawEllipse(blackpen, ex, ey, 50, 50);
this.Invalidate();
}
}
}