gpt4 book ai didi

c# - 鼠标拖动三角形逻辑

转载 作者:太空宇宙 更新时间:2023-11-03 23:19:13 25 4
gpt4 key购买 nike

我正在尝试通过简单的鼠标按下、拖动和鼠标弹起创建一个三角形。我有一个逻辑草图,我用线条画了草图,为了进一步说明和我一直在尝试的一些片段,但是,它从来没有像我试图在我的草图中绘制出来的那样。

有没有我做的不对,是不可能的,除了点击每个顶点还有其他解决方案吗?

Sketch

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
Vertex1 = e.Location; //First (left) Corner
}

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
Vertex2.X = e.X; //This creates a straight base from Vertex 1 to Vertex 2
Vertex2.Y = Vertex1.Y //'''' ''''''' ' '''''''' ''''
Vertex3.Y = e.Y; //The y is the same height the mouse was let go
Vertex3.X = (Vertex1.X + Vertex2.X) / 2; //The x is half way from the two corners

Point[] pts = new Point[3] { Vertex1, Vertex3, Vertex2};
g.DrawPolygon(Pen1, pts);
}

Vertex1 是第一个左角(鼠标按下)

顶点2是右角

Vertex3 是顶角

最佳答案

这一行是错误的:

Vertex3.X = (Vertex1.X - Vertex2.X) / 2; //The x is half way from the two corners

应该是

Vertex3.X = Vertex1.X + (Vertex2.X - Vertex1.X) / 2;

关于c# - 鼠标拖动三角形逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36023423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com