2020-05-15 22:34:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-05-19 23:49:47 +00:00
|
|
|
|
using System.Drawing;
|
2020-05-15 22:34:31 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace RyzStudio.Windows.Forms
|
|
|
|
|
{
|
|
|
|
|
public class ThreadControl
|
|
|
|
|
{
|
|
|
|
|
public static void AddControl(Control control, Control value)
|
|
|
|
|
{
|
|
|
|
|
if (control.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
control.Invoke(new MethodInvoker(() =>
|
|
|
|
|
{
|
|
|
|
|
control.Controls.Add(value);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
control.Controls.Add(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddItem(ListBox control, string value)
|
|
|
|
|
{
|
|
|
|
|
if (control.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
control.Invoke(new MethodInvoker(() => {
|
|
|
|
|
control.Items.Add(value);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
control.Items.Add(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Clear(ListBox control)
|
|
|
|
|
{
|
|
|
|
|
if (control.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
control.Invoke(new MethodInvoker(() => {
|
|
|
|
|
control.Items.Clear();
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
control.Items.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-19 23:49:47 +00:00
|
|
|
|
public static void Clear(FlowLayoutPanel control)
|
|
|
|
|
{
|
|
|
|
|
if (control.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
control.Invoke(new MethodInvoker(() => {
|
|
|
|
|
control.Controls.Clear();
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
control.Controls.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 22:34:31 +00:00
|
|
|
|
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 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 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 SetValue(Control control, string value)
|
|
|
|
|
{
|
|
|
|
|
if (control.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
control.Invoke(new MethodInvoker(() => {
|
|
|
|
|
control.Text = value;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
control.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetWidth(Control control, int value)
|
|
|
|
|
{
|
|
|
|
|
if (control.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
control.Invoke(new MethodInvoker(() => {
|
|
|
|
|
control.Width = value;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
control.Width = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-19 23:49:47 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 22:34:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|