0 c# location operators picturebox
可能重复:
如何在向两个点添加两个点的同时使+运算符工作?
我的代码
position.Location = (e.Location + pic1.Location) - bild_posi.Location;
Run Code Online (Sandbox Code Playgroud)
错误如:
the operator "+" isnt compatible with "System.Drawing.Point + System.Drawing.Point"
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
它取决于您希望如何将点添加到一起
您可以编写一个名为AddPoints的方法和一个名为SubtractPoints的方法,例如
private Point AddPoints(Point A, Point B)
{
return new Point(A.X + B.X, A.Y + B.Y);
}
private Point SubtractPoints(Point A, Point B)
{
return new Point(A.X - B.X, A.Y - B.Y);
}
Run Code Online (Sandbox Code Playgroud)
然后像使用它一样
position.Location = SubtractPoints(AddPoints(e.Location,pic1.Location),bild_posi.Location);
Run Code Online (Sandbox Code Playgroud)