改变椭圆的x/y坐标

3
作为一个大项目的一部分,我正在尝试找出如何移动一个对象(在这种情况下是椭圆)。这是导致我麻烦的代码部分:
//updating the position of the ellipse
let updatePoints (form : Form) (coords : vector3Dlist ) dtheta showtime =
  let mutable fsttuple = 0
  let mutable sndtuple = 0
  for i in 0..coords.Length-1 do
    fsttuple <- (int (round (fst coords.[i])))
    sndtuple <- (int (round (snd coords.[i])))
    (fillEllipseform.Paint.Add(fun draw->
    let brush=new SolidBrush(Color.Red)  
    draw.Graphics.FillEllipse(brush,fsttuple,sndtuple,10.0f,10.0f)))
    form.Refresh ()

该函数使用坐标列表来获取新的x和y值。这会导致出现"possible overload"语法错误。我认为我想要做的是这样的:
fillEllipseform.X <- fsttuple

如何准确地更改x/y坐标?当涉及到椭圆时,.NET库在F#示例方面非常有限。


1
Form does not have X and Y properties. It has a Location property of type Point. Try fillEllipseform.Location <- Point(fsttuple, sndtuple)` - gradbot
为了更符合惯用语,您可能希望删除这里的可变变量,实际上并不需要它们。 - Anton Schwaighofer
1个回答

3
您在这里遇到的问题是FillEllipse需要一个Brush,然后是4个int或4个float32。目前您正在传递混合类型,因此它不确定要选择哪个重载。
如果您选择了float32且不进行四舍五入(不确定vector3Dlist的类型),则工作版本将如下所示:
//updating the position of the ellipse
let updatePoints (form : Form) (coords : vector3Dlist ) dtheta showtime =
  let mutable fsttuple = 0.0f
  let mutable sndtuple = 0.0f
  for i in 0..coords.Length-1 do
    fsttuple <- fst coords.[i]
    sndtuple <- snd coords.[i]
    (fillEllipseform.Paint.Add(fun draw->
    let brush=new SolidBrush(Color.Red)  
    draw.Graphics.FillEllipse(brush,fsttuple,sndtuple,10.0f,10.0f)))
    form.Refresh ()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接