Added: PanelBook
This commit is contained in:
parent
a7b11a7db1
commit
15b462d2c0
37
2019/05/PanelBook.Designer.cs
generated
Normal file
37
2019/05/PanelBook.Designer.cs
generated
Normal file
@ -0,0 +1,37 @@
|
||||
namespace RyzStudio.Windows.Forms
|
||||
{
|
||||
partial class PanelBook
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
159
2019/05/PanelBook.cs
Normal file
159
2019/05/PanelBook.cs
Normal file
@ -0,0 +1,159 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
80
2019/05/PanelCollection.cs
Normal file
80
2019/05/PanelCollection.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RyzStudio.Windows.Forms
|
||||
{
|
||||
[ToolboxItem(true)]
|
||||
public class PanelCollection : CollectionBase
|
||||
{
|
||||
protected PanelBook panelBook = null;
|
||||
|
||||
public PanelCollection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public PanelCollection(PanelBook parent) : base()
|
||||
{
|
||||
panelBook = parent;
|
||||
}
|
||||
|
||||
public PanelBook Parent => panelBook;
|
||||
|
||||
public Panel this[int index] { get => (Panel)List[index]; set => List[index] = value; }
|
||||
|
||||
public int Add(Panel value) => List.Add(value);
|
||||
|
||||
public void AddRange(Panel[] pages)
|
||||
{
|
||||
foreach (Panel page in pages)
|
||||
{
|
||||
this.Add(page);
|
||||
}
|
||||
}
|
||||
|
||||
public int IndexOf(Panel value) => (List.IndexOf(value));
|
||||
|
||||
public void Insert(int index, Panel value) => List.Insert(index, value);
|
||||
|
||||
public void Remove(Panel value) => List.Remove(value);
|
||||
|
||||
public bool Contains(Panel value) => List.Contains(value);
|
||||
|
||||
protected override void OnInsertComplete(int index, object value)
|
||||
{
|
||||
base.OnInsertComplete(index, value);
|
||||
|
||||
if (panelBook != null)
|
||||
{
|
||||
panelBook.PageIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnRemoveComplete(int index, object value)
|
||||
{
|
||||
base.OnRemoveComplete(index, value);
|
||||
|
||||
if (panelBook != null)
|
||||
{
|
||||
if (panelBook.PageIndex == index)
|
||||
{
|
||||
if (index < InnerList.Count)
|
||||
{
|
||||
panelBook.PageIndex = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
panelBook.PageIndex = InnerList.Count - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user