-1

how to slide panel on mouseclick event in c# windows application i have tried this

panel1.Location = new Point(panel1.Location.X - i, panel1.Location.Y);
System.Threading.Thread.Sleep(10);
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • 1
    Why would you use `Thread.Sleep()`? It has no use for you.... and 10 means 10ms which is only 1/100th of a second so it wouldn't really do anything. – EpicKip Mar 08 '17 at 09:37
  • 1
    Also what do you even want.. How to slide? Hide? Mouseclick where? what? – EpicKip Mar 08 '17 at 09:38
  • Welcome to StackOverflow, Please take a look at [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) for some hints and tips about asking a good quality question. – phuzi Mar 08 '17 at 09:46

3 Answers3

0

If I understood you correctly, you want to move panel to the left. In that case you can write something like this:

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); 

    }
}
Nino
  • 6,931
  • 2
  • 27
  • 42
0

You should use Timer and on each tick just make some manipulations on the object.

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
}
mrogal.ski
  • 5,828
  • 1
  • 21
  • 30
0

This should work, please try this code

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;
}
imsome1
  • 1,182
  • 4
  • 22
  • 37