Archived
WIP: simplifying UI
This commit is contained in:
1 parent
b635db2be6
commit
c18b408df2
75 files changed
+931
-395
No files matched your search
-37
@@ -1,37 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RyzStudio.Windows.Forms
|
||||
{
|
||||
public class StackLayoutPanel : FlowLayoutPanel
|
||||
{
|
||||
public StackLayoutPanel() : base()
|
||||
{
|
||||
this.AutoScroll = true;
|
||||
this.FlowDirection = FlowDirection.TopDown;
|
||||
this.WrapContents = false;
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs eventargs)
|
||||
{
|
||||
base.OnResize(eventargs);
|
||||
|
||||
//int w = this.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth;
|
||||
int w = this.ClientRectangle.Width - 1;
|
||||
|
||||
foreach (Control item in this.Controls)
|
||||
{
|
||||
if (item.Width != w)
|
||||
{
|
||||
item.Width = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnControlAdded(ControlEventArgs e)
|
||||
{
|
||||
base.OnControlAdded(e);
|
||||
|
||||
OnResize(null);
|
||||
}
|
||||
|
||||
protected override void OnControlRemoved(ControlEventArgs e)
|
||||
{
|
||||
base.OnControlRemoved(e);
|
||||
|
||||
OnResize(null);
|
||||
}
|
||||
|
||||
public void AddControl(Control value)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
value.Margin = new Padding(0, 3, 0, 3);
|
||||
|
||||
this.Controls.Add(value);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
value.Margin = new Padding(0, 3, 0, 3);
|
||||
|
||||
this.Controls.Add(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RyzStudio.Windows.Forms
|
||||
{
|
||||
public class TFlatButton : Label
|
||||
{
|
||||
public class ButtonStyle
|
||||
{
|
||||
public Color BackColour { get; set; } = Color.Transparent;
|
||||
public Color PenColour { get; set; } = Color.Transparent;
|
||||
}
|
||||
|
||||
public enum FlatButtonState
|
||||
{
|
||||
Idle = 0,
|
||||
Hover,
|
||||
Down
|
||||
}
|
||||
|
||||
protected FlatButtonState controlState = FlatButtonState.Idle;
|
||||
|
||||
public TFlatButton() : base()
|
||||
{
|
||||
this.AutoSize = false;
|
||||
this.ImageAlign = ContentAlignment.MiddleCenter;
|
||||
this.TextAlign = ContentAlignment.MiddleCenter;
|
||||
|
||||
// customise
|
||||
this.StyleOver = new ButtonStyle()
|
||||
{
|
||||
BackColour = Color.FromArgb(51, 51, 51),
|
||||
PenColour = Color.White
|
||||
};
|
||||
this.StyleDown = new ButtonStyle()
|
||||
{
|
||||
BackColour = Color.FromArgb(179, 179, 179),
|
||||
PenColour = Color.Black
|
||||
};
|
||||
this.StyleDefault = new ButtonStyle()
|
||||
{
|
||||
BackColour = Color.White,
|
||||
PenColour = Color.Black
|
||||
};
|
||||
|
||||
this.VisualState = FlatButtonState.Idle;
|
||||
|
||||
this.Click += delegate { this.OnClick(null); };
|
||||
this.MouseEnter += delegate { this.VisualState = FlatButtonState.Hover; };
|
||||
this.MouseLeave += delegate { this.VisualState = FlatButtonState.Idle; };
|
||||
this.MouseDown += delegate { this.VisualState = FlatButtonState.Down; };
|
||||
this.MouseUp += delegate { this.VisualState = FlatButtonState.Idle; };
|
||||
}
|
||||
|
||||
protected FlatButtonState VisualState
|
||||
{
|
||||
get { return controlState; }
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case FlatButtonState.Idle:
|
||||
if (this.VisualState == FlatButtonState.Down)
|
||||
{
|
||||
updateButton(StyleOver);
|
||||
}
|
||||
else
|
||||
{
|
||||
updateButton(StyleDefault);
|
||||
}
|
||||
|
||||
break;
|
||||
case FlatButtonState.Hover:
|
||||
updateButton(StyleOver);
|
||||
break;
|
||||
case FlatButtonState.Down:
|
||||
updateButton(StyleDown);
|
||||
break;
|
||||
default:
|
||||
updateButton(StyleDefault);
|
||||
break;
|
||||
}
|
||||
|
||||
controlState = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateButton(ButtonStyle style)
|
||||
{
|
||||
this.ForeColor = style.PenColour;
|
||||
this.BackColor = style.BackColour;
|
||||
}
|
||||
|
||||
protected ButtonStyle StyleOver { get; set; } = new ButtonStyle();
|
||||
|
||||
protected ButtonStyle StyleDown { get; set; } = new ButtonStyle();
|
||||
|
||||
protected ButtonStyle StyleDefault { get; set; } = new ButtonStyle();
|
||||
|
||||
public void PerformClick()
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new MethodInvoker(() => {
|
||||
this.OnClick(null);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.OnClick(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
namespace RyzStudio.Windows.Forms
|
||||
{
|
||||
partial class THorizontalSeparator
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RyzStudio.Windows.Forms
|
||||
{
|
||||
public partial class THorizontalSeparator : System.Windows.Forms.UserControl
|
||||
{
|
||||
public THorizontalSeparator()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.MaximumSize = new Size(SystemInformation.VirtualScreen.Width, 2);
|
||||
}
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
|
||||
Graphics g = e.Graphics;
|
||||
|
||||
g.FillRectangle(new SolidBrush(Color.FromArgb(213, 223, 229)), new Rectangle(this.DisplayRectangle.Left, 0, this.DisplayRectangle.Width, 1));
|
||||
g.FillRectangle(new SolidBrush(Color.FromArgb(249, 251, 253)), new Rectangle(this.DisplayRectangle.Left, 1, this.DisplayRectangle.Width, 1));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
|
||||
namespace RyzStudio.Windows.Forms
|
||||
{
|
||||
public class TImageBox : System.Windows.Forms.PictureBox
|
||||
{
|
||||
public TImageBox() : base()
|
||||
{
|
||||
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
|
||||
this.ErrorImage = null;
|
||||
this.InitialImage = null;
|
||||
this.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
|
||||
}
|
||||
|
||||
protected override void OnCreateControl()
|
||||
{
|
||||
OnMouseLeave(null);
|
||||
|
||||
base.OnCreateControl();
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public new Image Image { get => base.Image; set => base.Image = value; }
|
||||
|
||||
[Category("Appearance"), Browsable(true)]
|
||||
public Image ImageNormal { get; set; }
|
||||
|
||||
[Category("Appearance"), Browsable(true)]
|
||||
public Image ImageHover { get; set; }
|
||||
|
||||
[Category("Appearance"), Browsable(true)]
|
||||
public Image ImageSelected { get; set; }
|
||||
|
||||
public bool IsSelected { get; set; } = false;
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e)
|
||||
{
|
||||
this.Image = this.ImageHover;
|
||||
|
||||
base.OnMouseEnter(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
this.Image = (this.IsSelected ? this.ImageSelected : this.ImageNormal);
|
||||
|
||||
base.OnMouseLeave(e);
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
this.Image = (this.IsSelected ? this.ImageSelected : this.ImageNormal);
|
||||
|
||||
base.OnLostFocus(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,497 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace RyzStudio.Windows.Forms
|
||||
{
|
||||
public class ThreadControl
|
||||
{
|
||||
public static void Add(Control control, Control value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Controls.Add(value);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Controls.Add(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Add(ListBox control, string value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Items.Add(value);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Items.Add(value);
|
||||
}
|
||||
}
|
||||
|
||||
//public static void Add(FlowLayoutPanel control, Control value)
|
||||
//{
|
||||
// if (control.InvokeRequired)
|
||||
// {
|
||||
// control.Invoke(new MethodInvoker(() => {
|
||||
// control.Controls.Add(value);
|
||||
// }));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// control.Controls.Add(value);
|
||||
// }
|
||||
//}
|
||||
|
||||
public static int Add(TreeView control, TreeNode value)
|
||||
{
|
||||
int n = -1;
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
n = control.Nodes.Add(value);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
n = control.Nodes.Add(value);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public static int Add(TreeNode control, TreeNode value)
|
||||
{
|
||||
int n = -1;
|
||||
|
||||
if (control.TreeView.InvokeRequired)
|
||||
{
|
||||
control.TreeView.Invoke(new MethodInvoker(() => {
|
||||
n = control.Nodes.Add(value);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
n = control.Nodes.Add(value);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public static int Add(DataGridView control, object[] value)
|
||||
{
|
||||
int n = -1;
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
n = control.Rows.Add(value);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
n = control.Rows.Add(value);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public static int Add(DataGridView control, object[] value, object tag)
|
||||
{
|
||||
int n = -1;
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
n = control.Rows.Add(value);
|
||||
control.Rows[n].Tag = tag;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
n = control.Rows.Add(value);
|
||||
control.Rows[n].Tag = tag;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public static TreeNode Add(TreeView control, string key, string text)
|
||||
{
|
||||
TreeNode rv = null;
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
rv = control.Nodes.Add(key, text);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = control.Nodes.Add(key, text);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static TreeNode Add(TreeNode control, string key, string text)
|
||||
{
|
||||
TreeNode rv = null;
|
||||
|
||||
if (control.TreeView.InvokeRequired)
|
||||
{
|
||||
control.TreeView.Invoke(new MethodInvoker(() => {
|
||||
rv = control.Nodes.Add(key, text);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = control.Nodes.Add(key, text);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static void AddLine(RichTextBox control, string text)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Text += text + Environment.NewLine;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Text += text + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear(ListBox control)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Items.Clear();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Items.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear(FlowLayoutPanel control)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Controls.Clear();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Controls.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear(TreeView control)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Nodes.Clear();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Nodes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear(Label control) => SetText(control, string.Empty);
|
||||
|
||||
public static void Clear(PictureBox control)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Image = null;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Image = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear(DataGridView control)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Rows.Clear();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Rows.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<T> FindChildControl<T>(Control control) where T : Control
|
||||
{
|
||||
List<T> rs = new List<T>();
|
||||
|
||||
foreach (Control item in control.Controls)
|
||||
{
|
||||
var ctr = item as T;
|
||||
if (ctr == null)
|
||||
{
|
||||
rs.AddRange(FindChildControl<T>(item));
|
||||
}
|
||||
else
|
||||
{
|
||||
rs.Add(ctr);
|
||||
}
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
public static string GetText(Control control, bool doTrim = true)
|
||||
{
|
||||
string rv = string.Empty;
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
rv = (doTrim ? control.Text?.Trim() : control.Text);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = (doTrim ? control.Text?.Trim() : control.Text);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static void SetEnable(Control control, bool value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Enabled = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetValue(NumericUpDown sender)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
if (sender.InvokeRequired)
|
||||
{
|
||||
sender.Invoke(new MethodInvoker(() => {
|
||||
rv = (int)sender.Value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = (int)sender.Value;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static string GetSelectedValue(ListBox sender)
|
||||
{
|
||||
string rv = string.Empty;
|
||||
|
||||
if (sender.InvokeRequired)
|
||||
{
|
||||
sender.Invoke(new MethodInvoker(() => {
|
||||
rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = (sender.SelectedItem == null) ? string.Empty : sender.SelectedItem.ToString();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static void SetHeight(Control control, int value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Height = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Height = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetSize(Control control, int width, int height) => SetSize(control, new Size(width, height));
|
||||
|
||||
public static void SetSize(Control control, Size value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Size = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Size = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetText(Control control, string text)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Text = text;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetTopMost(Form control, bool value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.TopMost = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.TopMost = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetValue(Control control, string value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Text = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetValue(PictureBox control, Image value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
control.Image = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Image = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetVisible(Control control, bool value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Visible = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Visible = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetVisible(Form control, bool value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
if (value)
|
||||
{
|
||||
control.ShowInTaskbar = value;
|
||||
control.Opacity = 100;
|
||||
control.Visible = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Visible = value;
|
||||
control.ShowInTaskbar = value;
|
||||
control.Opacity = 0;
|
||||
}
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
control.ShowInTaskbar = value;
|
||||
control.Opacity = 100;
|
||||
control.Visible = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Visible = value;
|
||||
control.ShowInTaskbar = value;
|
||||
control.Opacity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetWidth(Control control, int value)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new MethodInvoker(() => {
|
||||
control.Width = value;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Width = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user