배경이있는 버튼이 있습니다. mouseenter & mouseleave 이벤트를 만들었습니다. mouseleave 이벤트에서 마우스 커서가 2 좌표 밖에 있으면 mouseleave 이벤트가 트리거됩니다.
private void Button_SpanMouseEnter(object sender, EventArgs e)
{
Button x = sender as Button;
x.Size = new Size(500, 250);
x.Location = new Point(0, 0);
}
private void Button_SpanMouseLeave(object sender, EventArgs e)
{
Button x = sender as Button;
//If cursor is outside of this coordinates(0,0) & (250,125)
//it will trigger this size
x.Size = new Size(250,125);
x.Location = new Point(0, 0);
}
내 문제는 내가 500X250 직사각형으로 떠날 때 mouseleave를 트리거합니다. 250X125 직사각형으로 트리거하고 싶습니다.
시도중인 효과를 보관하려면 Button_MouseLeave
이벤트 대신 이벤트를 사용해야합니다 MouseMove
. 따라서 Button_SpanMouseLeave
이벤트를 제거 하고 다음을 추가하십시오.
private void button1_MouseMove(object sender, MouseEventArgs e)
{
Button x = sender as Button;
Point p = PointToClient(System.Windows.Forms.Control.MousePosition);
if (p.X > 250|| p.Y >125)
{
button1.Size = new Size(250, 125);
button1.Location = new Point(0, 0);
}
}
편집하다
실제로 PointToClient 메서드는 전혀 필요하지 않습니다. 따라서 코드는 다음과 같습니다.
private void button1_MouseMove(object sender, MouseEventArgs e)
{
Button x = sender as Button;
if (e.X > 250|| e.Y >125)
{
x.Size = new Size(250, 125);
x.Location = new Point(0, 0);
}
}
편집 2
좋아, 버튼이 위치하지 않으면 0,0
다음 PointToClient
과 같이 사용하는 것이 좋습니다 .
private void button1_MouseMove(object sender, MouseEventArgs e)
{
Button x = sender as Button;
Point p = PointToClient(System.Windows.Forms.Control.MousePosition);
this.label1.Text = p.X.ToString() + " " + p.Y.ToString();
if (p.X > x.Location.X + 250 || p.Y > x.Location.Y+125)
{
button1.Size = new Size(250, 125);
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다