@Jan Dvorak , you can try to use three panels two buttons and two timers to make a expandable.
Here is a code example you could refer to.(The right panel)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
centerpanel.Parent = this;
leftpanel.Parent = this;
rightpanel.Parent = this;
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(700, 400);
}
bool isRight = false;
bool isLeft = false;
private System.Timers.Timer myTimer;
private void button1_Click(object sender, EventArgs e)
{
isRight = !isRight;
rightpanel.Visible = true;
centerpanel.BringToFront();
this.myTimer = new System.Timers.Timer(10);
this.myTimer.Elapsed += new System.Timers.ElapsedEventHandler(right_Elapsed);
this.myTimer.AutoReset = true;
this.myTimer.Enabled = true;
this.myTimer.Start();
}
private void right_Elapsed(object sender, ElapsedEventArgs e)
{
if (isRight)
{
if (this.Width + 15 > rightpanel.Width * 2)
{
this.myTimer.Enabled = false;
this.myTimer.Stop();
}
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate { Width += 10; }));
rightpanel.Invoke(new MethodInvoker(delegate { rightpanel.Left += 10; }));
}
}
else
{
if (this.Width - 10 < rightpanel.Width)
{
this.myTimer.Enabled = false;
this.myTimer.Stop();
rightpanel.Invoke(new MethodInvoker(delegate { rightpanel.Visible = false; }));
}
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate { Width -= 10; }));
rightpanel.Invoke(new MethodInvoker(delegate { rightpanel.Left -= 10; }));
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
rightpanel.Visible = false;
leftpanel.Visible = false;
button1.Parent = centerpanel;
button1.Location = new Point(257, 0);
button2.Parent = centerpanel;
button2.Location = new Point(0, 0);
this.FormBorderStyle = FormBorderStyle.None;
}
}
Result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.