Here's a quick sketch of one way to go about the kind of interface you want:
1. Create a WinForm App with a Main Form named 'MainForm like this: [
^].
a. add Three Panels as shown; none of them are Docked; they have their Anchor properties set so if the Form is re-sized they will re-size appropriately.
b. add a Button to the pnlMenu, 'btnInitialize, this will trigger the initial creation of the Views/UserControls as shown in the code.
2. add a Timer component to the Form, 'timer1. Set its 'Interval to 50ms.
3. Create a UserControl, 'ucType1Child1, size 560,508, background-color Alice-Blue. Put a TextBox on it, 'textBox1.
Code for the MainForm:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace Dec12_PageSlider
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private ucType1Child1 currentUC;
private ucType1Child1 nextUC;
private Dictionary<Button, ucType1Child1> dctBtnToUc = new Dictionary<Button, ucType1Child1>();
private Button clickedButton;
private void btnInitialize_Click(object sender, EventArgs e)
{
if (pnlContent.Controls.Count > 0)
{
pnlContent.Controls.Clear();
dctBtnToUc.Clear();
}
for (int i = 0; i < 5; i++)
{
ucType1Child1 uc1 = new ucType1Child1 {Anchor = AnchorStyles.None, Dock = DockStyle.None};
uc1.setText("View " + (i + 1));
pnlContent.Controls.Add(uc1);
uc1.Left = -uc1.Width - 6;
uc1.Top = 1;
Button btn = new Button {BackColor = Color.GhostWhite, Text = string.Format("View {0}", (i+ 1).ToString())};
pnlNavigator.Controls.Add(btn);
btn.Left = 50;
btn.Top = (i*65) + 26;
btn.Click += viewBtn_Click;
dctBtnToUc.Add(btn, uc1);
dctBtnToUc.Keys.First().PerformClick();
}
}
private void viewBtn_Click(object sender, EventArgs e)
{
nextUC = dctBtnToUc[sender as Button];
if (currentUC == nextUC) return;
if (nextUC.Left > 0) nextUC.Left = -nextUC.Width - 6;
nextUC.BringToFront();
currentUC = nextUC;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
currentUC.Left += 50;
if (currentUC.Left >= 3)
{
timer1.Stop();
currentUC.Left = 3;
}
}
}
}
The UserControl, 'ucChild1Type1 is very simple:
using System.Windows.Forms;
namespace Dec12_PageSlider
{
public partial class ucType1Child1 : UserControl
{
public ucType1Child1()
{
InitializeComponent();
}
public void setText(string text)
{
textBox1.Text = text;
}
}
}
Here's what it looks like running after 'button1 has been clicked and the five views are created: here I've just clicked on the 'View 5" Button and that view has scrolled into view in the Content Panel: [
^].
Comments:
1. Of course, there are a lot of things here that would need to be worked out to go beyond just a prototype showing proof-of-concept.
2. all those hard-coded offsets for positioning would need to be transformed into calculated offsets.
3. the issue of re-sizing the view/usercontrol when the Form is re-sized is not addressed here, although that's not technically difficult.
Remember this is example is primarily meant be for educational purposes, the standards one would want for "production code" are not even attempted here.