This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
linear-app-launcher/RyzStudio/Windows/Forms/PanelBook.cs

160 lines
3.7 KiB
C#
Raw Normal View History

2020-04-27 12:17:13 +00:00
namespace RyzStudio.Windows.Forms
{
using System;
using System.ComponentModel;
using System.Windows.Forms;
[ToolboxItem(true)]
public partial class PanelBook : UserControl
{
protected PanelCollection panelCollection = null;
public PanelBook()
{
InitializeComponent();
panelCollection = new PanelCollection(this);
}
public Panel ActivePanel { get; set; } = null;
[Category("Collection")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public PanelCollection Pages
{
get { return panelCollection; }
}
[Category("Collection")]
public int SelectedIndex
{
get
{
if (panelCollection.Count <= 0)
{
return -1;
}
return panelCollection.IndexOf(this.ActivePanel);
}
set
{
if (panelCollection.Count <= 0)
{
return;
}
if (value < 0)
{
return;
}
if (value > (panelCollection.Count - 1))
{
return;
}
if (value == this.SelectedIndex)
{
return;
}
ActivatePanel(value);
}
}
protected internal int PageIndex
{
get
{
return panelCollection.IndexOf(this.ActivePanel);
}
set
{
if (panelCollection.Count <= 0)
{
ActivatePanel(-1);
return;
}
if ((value < -1) || (value >= panelCollection.Count))
{
throw new ArgumentOutOfRangeException("PageIndex", value, "The page index must be between 0 and " + Convert.ToString(panelCollection.Count - 1));
}
ActivatePanel(value);
}
}
protected internal void ActivatePanel(int index)
{
if ((panelCollection.Count == 0) && (index >= panelCollection.Count) && (index <= 0))
{
return;
}
Panel p = (Panel)panelCollection[index];
ActivatePage(p);
}
protected internal void ActivatePage(Panel page)
{
if (this.ActivePanel != null)
{
this.ActivePanel.Visible = false;
}
this.ActivePanel = page;
if (this.ActivePanel != null)
{
this.ActivePanel.Parent = this;
if (!this.Contains(this.ActivePanel))
{
this.Container.Add(this.ActivePanel);
}
this.ActivePanel.Dock = DockStyle.Fill;
this.ActivePanel.Visible = true;
this.ActivePanel.BringToFront();
}
if (this.ActivePanel != null)
{
this.ActivePanel.Invalidate();
}
else
{
this.Invalidate();
}
}
#if DEBUG
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (this.DesignMode)
{
this.Invalidate();
}
}
#endif
protected override void DestroyHandle()
{
base.DestroyHandle();
foreach (Panel p in panelCollection)
{
p.Dispose();
}
}
}
}