From 96af2b6b3d48569307be1e414b8cb9ba0ae2442b Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 20 Jun 2020 13:21:11 +0100 Subject: [PATCH] Changed: updated threadcontrols --- MainForm.cs | 2 +- RyzStudio/Windows/Forms/ThreadControl.cs | 238 +++++++++++++++++++---- 2 files changed, 204 insertions(+), 36 deletions(-) diff --git a/MainForm.cs b/MainForm.cs index d73a32e..da19af2 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -430,7 +430,7 @@ namespace AppLauncher TTilePanelLayout panel = new TTilePanelLayout(item); maxWidth = Math.Max(maxWidth, panel.Width); - ThreadControl.AddControl(flowLayoutPanel1, panel); + ThreadControl.Add(flowLayoutPanel1, panel); } } diff --git a/RyzStudio/Windows/Forms/ThreadControl.cs b/RyzStudio/Windows/Forms/ThreadControl.cs index d1c76db..6b14670 100644 --- a/RyzStudio/Windows/Forms/ThreadControl.cs +++ b/RyzStudio/Windows/Forms/ThreadControl.cs @@ -10,7 +10,7 @@ namespace RyzStudio.Windows.Forms { public class ThreadControl { - public static void AddControl(Control control, Control value) + public static void Add(Control control, Control value) { if (control.InvokeRequired) { @@ -25,7 +25,7 @@ namespace RyzStudio.Windows.Forms } } - public static void AddItem(ListBox control, string value) + public static void Add(ListBox control, string value) { if (control.InvokeRequired) { @@ -39,6 +39,130 @@ namespace RyzStudio.Windows.Forms } } + //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) @@ -82,6 +206,52 @@ namespace RyzStudio.Windows.Forms } } + 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 FindChildControl(Control control) where T : Control { List rs = new List(); @@ -120,6 +290,21 @@ namespace RyzStudio.Windows.Forms 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; @@ -156,38 +341,6 @@ namespace RyzStudio.Windows.Forms return rv; } - public static void SetClear(Label control) => SetText(control, string.Empty); - - public static void SetClear(PictureBox control) - { - if (control.InvokeRequired) - { - control.Invoke(new MethodInvoker(() => - { - control.Image = null; - })); - } - else - { - control.Image = null; - } - } - - public static void SetClear(DataGridView control) - { - if (control.InvokeRequired) - { - control.Invoke(new MethodInvoker(() => - { - control.Rows.Clear(); - })); - } - else - { - control.Rows.Clear(); - } - } - public static void SetHeight(Control control, int value) { if (control.InvokeRequired) @@ -261,6 +414,21 @@ namespace RyzStudio.Windows.Forms } } + 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) @@ -326,4 +494,4 @@ namespace RyzStudio.Windows.Forms } } -} +} \ No newline at end of file