From 1a8904bdc271917a2e1df4379ef50963ceff40f7 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 May 2020 09:47:59 +0100 Subject: [PATCH] Changed: ThreadControl --- RyzStudio/Windows/Forms/ThreadControl.cs | 158 ++++++++++++++++------- 1 file changed, 113 insertions(+), 45 deletions(-) diff --git a/RyzStudio/Windows/Forms/ThreadControl.cs b/RyzStudio/Windows/Forms/ThreadControl.cs index eb441eb..d1c76db 100644 --- a/RyzStudio/Windows/Forms/ThreadControl.cs +++ b/RyzStudio/Windows/Forms/ThreadControl.cs @@ -39,6 +39,21 @@ namespace RyzStudio.Windows.Forms } } + 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) @@ -67,6 +82,26 @@ namespace RyzStudio.Windows.Forms } } + public static List FindChildControl(Control control) where T : Control + { + List rs = new List(); + + foreach (Control item in control.Controls) + { + var ctr = item as T; + if (ctr == null) + { + rs.AddRange(FindChildControl(item)); + } + else + { + rs.Add(ctr); + } + } + + return rs; + } + public static string GetText(Control control, bool doTrim = true) { string rv = string.Empty; @@ -103,7 +138,7 @@ namespace RyzStudio.Windows.Forms return rv; } - public string GetSelectedValue(ListBox sender) + public static string GetSelectedValue(ListBox sender) { string rv = string.Empty; @@ -121,6 +156,38 @@ 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) @@ -135,6 +202,51 @@ namespace RyzStudio.Windows.Forms } } + 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) @@ -213,49 +325,5 @@ namespace RyzStudio.Windows.Forms } } - public static void SetSize(Control control, int width, int height) - { - if (control.InvokeRequired) - { - control.Invoke(new MethodInvoker(() => { - control.Width = width; - control.Height = height; - })); - } - else - { - control.Width = width; - control.Height = 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 SetTopMost(Form control, bool value) - { - if (control.InvokeRequired) - { - control.Invoke(new MethodInvoker(() => { - control.TopMost = value; - })); - } - else - { - control.TopMost = value; - } - } - } }