Changed: ThreadControl

This commit is contained in:
Ray 2020-05-21 09:47:59 +01:00
parent b73a03683c
commit 1a8904bdc2

View File

@ -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) public static void Clear(ListBox control)
{ {
if (control.InvokeRequired) if (control.InvokeRequired)
@ -67,6 +82,26 @@ namespace RyzStudio.Windows.Forms
} }
} }
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) public static string GetText(Control control, bool doTrim = true)
{ {
string rv = string.Empty; string rv = string.Empty;
@ -103,7 +138,7 @@ namespace RyzStudio.Windows.Forms
return rv; return rv;
} }
public string GetSelectedValue(ListBox sender) public static string GetSelectedValue(ListBox sender)
{ {
string rv = string.Empty; string rv = string.Empty;
@ -121,6 +156,38 @@ namespace RyzStudio.Windows.Forms
return rv; 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) public static void SetHeight(Control control, int value)
{ {
if (control.InvokeRequired) 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) public static void SetValue(Control control, string value)
{ {
if (control.InvokeRequired) 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;
}
}
} }
} }