2017-03-08 7 views
-1
c# 창에 mouseclick 이벤트에 패널을 슬라이드하는 방법

응용 프로그램 은 내가 시도 내가 제대로 이해하면C#에서 마우스 클릭 이벤트에 패널을 자동 숨기기하는 방법을

panel1.Location = new Point(panel1.Location.X - i, panel1.Location.Y); 
System.Threading.Thread.Sleep(10); 
+1

가 왜'에 Thread.sleep()'사용하는 것이이 코드를보십시오? 그것은 당신에게 쓸모가 없습니다. 그리고 10은 1/100th 1 초의 10ms를 의미하므로 아무 것도하지 않습니다. – EpicKip

+1

또한 무엇을 원하니 .. 어떻게 미끄러 져? 숨는 장소? 어디서? 뭐? – EpicKip

+0

StackOverflow에 오신 것을 환영합니다. [좋은 질문을하는 방법?] (http://stackoverflow.com/help/how-to-ask) 좋은 힌트와 좋은 질문에 대한 조언. – phuzi

답변

0

, 당신은 왼쪽 패널을 이동하려면이 .

private void panel1_MouseClick(object sender, MouseEventArgs e) 
{ 
    //declare step in pixel which will be used to move panel 
    int xMoveStep = 3; 
    //repeat this block of code until panel is hidden under form's left border, until 
    //panels top right is less than 0 
    while (this.panel1.Right > 0) 
    { 
     //move it to left 
     this.panel1.Left = this.panel1.Left - xMoveStep; 
     //pause for 10 milliseconds 
     Thread.Sleep(10); 

    } 
} 
0

당신은 단지 개체에 대한 몇 가지 조작을 Timer을 사용하고 각 틱에서한다 :이 경우 당신은 다음처럼 작성할 수 있습니다.

Timer m_Timer = null; // placeholder for your timer 

private void panel1_MouseClick(object sender, MouseEventArgs e) 
{ 
    if(m_Timer != null) return; 
    // if timer is not null means you're animating your panel so do not want to perform any other animations 

    m_Timer = new Timer(); // instantiate timer 
    m_Timer.Interval = 1000/30; // 30 frames per second; 
    m_Timer.Tick += OnTimerTick; // set method handler 
    m_Timer.Start(); // start the timer 
} 

int m_CurrentFrame = 0; // current frame 

void OnTimerTick(object sender, EventArgs e) 
{ 
    const int LAST_FRAME_INDEX = 150; // maximum frame you can reach 

    if(m_CurrenFrame > LAST_FRAME_INDEX) // if max reached 
    { 
     m_Timer.Stop(); // stop timer 
     m_Timer.Dispose(); // dispose it for the GC 
     m_Timer = null; // set it's reference to null 
     m_CurrentFrame = 0; // reset current frame index 
     return; // return from the event 
    } 

    this.Invoke(new MethodDelegate(() => { // invoke this on the UI thread 
     panel1.Location = new Point(panel1.Location.X - m_CurrenFrame, panel1.Location.Y); 
    }); 
    m_CurrentFrame++; // increase current frame index 
} 
0

이 작동합니다,

private void frmTest_MouseMove(object sender, MouseEventArgs e) 
{ 
    if (e.Location.X >= panel1.Bounds.X && e.Location.X <= (panel1.Bounds.X + panel1.Bounds.Width) && e.Location.Y >= panel1.Bounds.Y && e.Location.Y <= (panel1.Bounds.Y + panel1.Bounds.Width)) 
    { 
    panel1.Visible = false; 
    } 
    else 
    { 
    panel1.Visible = true; 
    } 
} 

private void panel1_MouseMove(object sender, MouseEventArgs e) 
{ 
    panel1.Visible = false; 
}