You can expand, hide, and lock the sidebar. By default, the added sidebar is not displayed and is triggered by the mouse hover event MouseHover. The Sidebar is actually a form or container. The expanded action must gradually increase the width within a period of time. I use Panel as the container carrier, gradually add the Width attribute of the Panel in a thread. Hiding is mainly implemented by the Visible attribute of the Panel. The hiding condition is determined by judging whether the mouse position is beyond the boundary of the sidebar. Locking means that the Panel is always displayed, so that the hidden Panel function is not executed.
Interface
Related code:
Expand:
Private void toolStripButton2_MouseHover (object sender, EventArgs e)
{
// Hover the cursor over the event to expand
If (! This. panel2.Visible) // panel2 is the sidebar container
{
Thread ts = new Thread (new ParameterizedThreadStart (TaskShowPanel ));
Ts. Is true; // set it to a background thread.
Ts. Priority = ThreadPriority. Normal; // set the Priority.
Ts. Start (Object) 245); // The expanded Panel width is 245.
}
}
// Defined thread execution function
Private void TaskShowPanel (Object ParObject)
{
Int w = (int) ParObject;
For (int I = 0; I <= w; I ++)
{
ShowPanel (this. panel2, I );
}
}
Private delegate void SetTextCallback (Panel p1, int w );
/// <Summary>
/// Expand an action
/// </Summary>
/// <Param name = "p1"> panel container </param>
/// <Param name = "w"> width </param>
Private void ShowPanel (Panel p1, int w)
{
// Cross-thread access
Try
{
If (p1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback (ShowPanel );
P1.Invoke (d, new Object [] {p1, w });
}
Else
{
P1.Width = w;
If (! P1.Visible)
{
P1.Visible = true;
}
}
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message, "ShowPanel function execution error ");
}
}
Hide:
Private void listView1_MouseMove (object sender, MouseEventArgs e)
{
Point panelPoint = this. PointToClient (Control. MousePosition); // The current mouse position
// This. Start position of panel2.Location. X panel2
// This. panel2.Width the width of panel2
If (this. panel2.Visible & (panelPoint. X> (this. panel2.Location. X + this. panel2.Width )))
{
This. panel2.Visible = false;
}
}
Lock:
Private void button#click (object sender, EventArgs e)
{
// Delete hidden events
This. listView1.MouseMove-= new System. Windows. Forms. MouseEventHandler (this. listview#mousemove );
}