문제
이 이벤트를 사용하면 라벨이 사라지는데 어떻게 해야 하나요?
private void label4_MouseMove(object sender, MouseEventArgs e)
{
label4.Location = new Point(Cursor.Position.X, Cursor.Position.Y);
}
해결책
위치 label4
컨테이너에 상대적입니다(Form
또는 상위 컨트롤), 커서 위치는 화면을 기준으로 할 수 있습니다.
위치를 조정해야 합니다.예를 들어 컨테이너가 다음과 같은 경우 Form
화면에서 해당 위치를 찾고 화면을 기준으로 커서의 위치를 계산할 수 있습니다.
이는 원인에 대한 하나의 가능성일 뿐이지만, 이런 일이 많이 발생합니다. :)
다른 팁
handle these three event ...
Control actcontrol;
Point preloc;
void label1_Mousedown(object sender, MouseEventArgs e)
{
actcontrol = sender as Control;
preloc = e.Location;
Cursor = Cursors.Default;
}
void label1_MouseMove(object sender, MouseEventArgs e)
{
if (actcontrol == null || actcontrol != sender)
return;
var location = actcontrol.Location;
location.Offset(e.Location.X - preloc.X, e.Location.Y - preloc.Y);
actcontrol.Location = location;
}
void label1_MouseUp(object sender, MouseEventArgs e)
{
actcontrol = null;
Cursor = Cursors.Default;
}
Form의 PointToclient () 함수를 사용하여 마우스 x/y 좌표를 양식과 관련된 점으로 변환하여 수행해야합니다.
편집 : 마우스 이벤트 사용 Args 객체 속성을 대신 사용하십시오.
Label1.Location = New Point(e.X, e.Y)
PS이 PC에서 VB, C# 없음
요소의 위치는 부모와 관련이 있습니다. 이 경우 절대 마우스 위치를 해당 위치로 사용하고 있습니다.
마우스 위치를 부모 요소의 좌표계로 변환해야합니다.
사용 PointToClient
레이블의 상위 요소의 메소드.
제휴하지 않습니다 StackOverflow