当尝试使用代码时,会出现两个标签,当移动时,屏幕会从移动的位置变为白色。我想用鼠标移动单标签移动。
bool mDown = false;
private void label13_MouseMove(object sender, MouseEventArgs e)
{
if (mDown)
{
label13.Location = e.Location;
}
}
private void label13_MouseDown(object sender, MouseEventArgs e)
{
mDown = true;
}
private void label13_MouseUp(object sender, MouseEventArgs e)
{
mDown = false;
}
答案 0 :(得分:0)
e.Location为您提供相对于被点击的控件的鼠标位置。所以要解决这个问题,而不是
def get_letter_grade(score):
try:
score = float(score)
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
except ValueError:
print("score is not an number")
return false
使用
var pos = this.PointToClient(Cursor.Position); label13.Location = new Point(pos.X - offset.X, pos.Y - offset.Y);`
创建偏移量变量作为表单的属性(类型为Point)并在鼠标按下事件中初始化它:
label13.Location = e.Location;