我使用以下代码在C#中拖放Button,当我的Form.RightToLeftLayout = False时,它就像魅力一样 但 当我设置RightToLeftLayout = True时 它不起作用并将控制方向移动错误!!!
public partial class Form1 : Form
{
int xPosition;
int yPosition;
bool isDraged;
public Form1()
{
InitializeComponent();
}
private void btnMoveable_MouseDown(object sender, MouseEventArgs e)
{
this.Cursor = Cursors.SizeAll;
xPosition = e.X;
yPosition = e.Y;
isDraged = true;
}
private void btnMoveable_MouseUp(object sender, MouseEventArgs e)
{
isDraged = false;
this.Cursor = Cursors.Default;
}
private void btnMoveable_MouseMove(object sender, MouseEventArgs e)
{
if (isDraged)
{
btnMoveable.Left = btnMoveable.Left + e.X - xPosition;
btnMoveable.Top = btnMoveable.Top + e.Y - yPosition;
}
}
}
答案 0 :(得分:2)
嗯,您正在发现RightToLeft的实施方式。一切仍处于正常的逻辑位置,但坐标系沿Y轴镜像。因此,沿X轴的运动被反转。你需要适应这一点。修正:
int dx = e.X - xPosition;
if (this.RightToLeft == RightToLeft.Yes) dx = -dx;
btnMoveable.Left = btnMoveable.Left + dx;