Changed: modernise panelbook

This commit is contained in:
Ray 2020-06-14 23:22:09 +01:00
parent 53e4a1e84e
commit 3782bbfc44
3 changed files with 95 additions and 122 deletions

View File

@ -28,8 +28,7 @@
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
components = new System.ComponentModel.Container();
}
#endregion

View File

@ -1,12 +1,72 @@
namespace RyzStudio.Windows.Forms
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
[ToolboxItem(true)]
public partial class PanelBook : UserControl
{
public class PanelCollection : CollectionBase
{
protected PanelBook panelBook = null;
public PanelCollection(PanelBook parentPanelBook) : base()
{
panelBook = parentPanelBook;
}
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) => Array.ForEach(pages, x => this.Add(x));
public bool Contains(Panel value) => List.Contains(value);
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);
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;
}
}
}
}
}
protected PanelCollection panelCollection = null;
public PanelBook()
@ -14,51 +74,49 @@
InitializeComponent();
panelCollection = new PanelCollection(this);
}
public Panel ActivePanel { get; set; } = null;
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Panel ActivePanel { get; protected set; } = null;
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override bool AutoScroll { get => base.AutoScroll; set => base.AutoScroll = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Size AutoScrollMargin { get => base.AutoScrollMargin; set => base.AutoScrollMargin = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Size AutoScrollMinSize { get => base.AutoScrollMinSize; set => base.AutoScrollMinSize = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override Image BackgroundImage { get => base.BackgroundImage; set => base.BackgroundImage = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override ImageLayout BackgroundImageLayout { get => base.BackgroundImageLayout; set => base.BackgroundImageLayout = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new ImeMode ImeMode { get => base.ImeMode; set => base.ImeMode = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override RightToLeft RightToLeft { get => base.RightToLeft; set => base.RightToLeft = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new bool UseWaitCursor { get => base.UseWaitCursor; set => base.UseWaitCursor = value; }
[Category("Collection")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public PanelCollection Pages
{
get { return panelCollection; }
}
public PanelCollection Pages => panelCollection;
[Category("Collection")]
public int SelectedIndex
{
get
{
if (panelCollection.Count <= 0)
{
return -1;
}
return panelCollection.IndexOf(this.ActivePanel);
}
get => (panelCollection.Count <= 0) ? -1 : 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;
}
if (panelCollection.Count <= 0) return;
if (value < 0) return;
if (value > (panelCollection.Count - 1)) return;
if (value == this.SelectedIndex) return;
ActivatePanel(value);
}
@ -66,10 +124,7 @@
protected internal int PageIndex
{
get
{
return panelCollection.IndexOf(this.ActivePanel);
}
get => panelCollection.IndexOf(this.ActivePanel);
set
{
if (panelCollection.Count <= 0)
@ -154,6 +209,5 @@
}
}
}
}
}

View File

@ -1,80 +0,0 @@
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;
}
}
}
}
}
}