Initial commit
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Xylem.Common.Utils.UiInvoker
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class for UI invoking
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public static class UiInvoker
|
||||
{
|
||||
/// <summary>
|
||||
/// Control invoker for process bar.
|
||||
/// </summary>
|
||||
/// <remarks date="2020-Dec-22" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public static void ProgressBarInvoker(ProgressBar progressBar, Int32 value = 0, Boolean visible = true)
|
||||
{
|
||||
if (progressBar == null) return;
|
||||
if (value > 100) value = 100;
|
||||
if (value < 0) value = 0;
|
||||
if (progressBar.InvokeRequired)
|
||||
{
|
||||
progressBar.Invoke(new Action(() =>
|
||||
{
|
||||
progressBar.Visible = visible;
|
||||
progressBar.Value = value;
|
||||
progressBar.Update();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar.Visible = visible;
|
||||
progressBar.Value = value;
|
||||
progressBar.Update();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Control invoker for enable and disable. The control remains visible.
|
||||
/// The last element gets always the focus.
|
||||
/// </summary>
|
||||
/// <param name="ctrl"></param>
|
||||
/// <param name="enabled"></param>
|
||||
/// <remarks date="2020-Dec-22" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
/// <remarks date="2021-Apr-09" author="Thomas Wiedebusch">
|
||||
/// - Avoid recurrent activation of identical state.
|
||||
/// </remarks>
|
||||
public static void ControlEnableInvoker(Control ctrl, Boolean enabled)
|
||||
{
|
||||
if (ctrl == null) return;
|
||||
if (ctrl.InvokeRequired)
|
||||
{
|
||||
ctrl.Invoke(new Action(() =>
|
||||
{
|
||||
if (ctrl.Enabled == enabled) return;
|
||||
|
||||
ctrl.Enabled = enabled;
|
||||
ctrl.Update();
|
||||
ctrl.Focus();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctrl.Enabled == enabled) return;
|
||||
|
||||
ctrl.Enabled = enabled;
|
||||
ctrl.Update();
|
||||
ctrl.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Control invoker to hide or display control.
|
||||
/// </summary>
|
||||
/// <param name="ctrl"></param>
|
||||
/// <param name="visible"></param>
|
||||
/// <remarks date="2020-Dec-23" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
/// <remarks date="2021-Apr-09" author="Thomas Wiedebusch">
|
||||
/// - Avoid recurrent activation of identical state.
|
||||
/// </remarks>
|
||||
public static void ControlViewInvoker(Control ctrl, Boolean visible)
|
||||
{
|
||||
if (ctrl == null) return;
|
||||
if (ctrl.InvokeRequired)
|
||||
{
|
||||
ctrl.Invoke(new Action(() =>
|
||||
{
|
||||
if (ctrl.Visible == visible) return;
|
||||
|
||||
ctrl.Visible = visible;
|
||||
ctrl.Update();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctrl.Visible == visible) return;
|
||||
|
||||
ctrl.Visible = visible;
|
||||
ctrl.Update();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Control invoker with message, visibility on and new color.
|
||||
/// </summary>
|
||||
/// <remarks date="2021-Feb-25" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
/// <remarks date="2021-Apr-09" author="Thomas Wiedebusch">
|
||||
/// - Avoid recurrent activation of identical state.
|
||||
/// </remarks>
|
||||
public static void ControlInvoker(Control ctrl, Color color, String msg = "", Boolean visible = true)
|
||||
{
|
||||
if (ctrl == null) return;
|
||||
if (ctrl.InvokeRequired)
|
||||
{
|
||||
ctrl.Invoke(new Action(() =>
|
||||
{
|
||||
if (ctrl.Visible == visible && ctrl.Text == msg && ctrl.ForeColor == color) return;
|
||||
|
||||
ctrl.Visible = visible;
|
||||
ctrl.ForeColor = color;
|
||||
ctrl.Text = $@"{msg}";
|
||||
ctrl.Update();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctrl.Visible == visible && ctrl.Text == msg && ctrl.ForeColor == color) return;
|
||||
|
||||
ctrl.Visible = visible;
|
||||
ctrl.ForeColor = color;
|
||||
ctrl.Text = $@"{msg}";
|
||||
ctrl.Update();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tool strip invoker with message, visibility on and new color.
|
||||
/// </summary>
|
||||
/// <remarks date="2021-Feb-25" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
/// <remarks date="2021-Apr-09" author="Thomas Wiedebusch">
|
||||
/// - Avoid recurrent activation of identical state.
|
||||
/// </remarks>
|
||||
public static void ToolStripLabelInvoker(ToolStripStatusLabel ctrl, Color color, String msg = "", Boolean visible = true)
|
||||
{
|
||||
if (ctrl?.GetCurrentParent() == null) return;
|
||||
if (ctrl.GetCurrentParent().InvokeRequired)
|
||||
{
|
||||
ctrl.GetCurrentParent().Invoke(new Action(() =>
|
||||
{
|
||||
if (ctrl.Visible == visible && ctrl.Text == msg && ctrl.ForeColor == color) return;
|
||||
|
||||
ctrl.Visible = visible;
|
||||
ctrl.ForeColor = color;
|
||||
ctrl.Text = $@"{msg}";
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctrl.Visible == visible && ctrl.Text == msg && ctrl.ForeColor == color) return;
|
||||
|
||||
ctrl.Visible = visible;
|
||||
ctrl.ForeColor = color;
|
||||
ctrl.Text = $@"{msg}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tool strip invoker with message, visibility on and new color.
|
||||
/// </summary>
|
||||
/// <remarks date="2021-Feb-25" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
/// <remarks date="2021-Apr-09" author="Thomas Wiedebusch">
|
||||
/// - Avoid recurrent activation of identical state.
|
||||
/// </remarks>
|
||||
public static void ToolStripInvoker(ToolStrip ctrl, Color color, String msg = "", Boolean visible = true)
|
||||
{
|
||||
if (ctrl == null) return;
|
||||
if (ctrl.InvokeRequired)
|
||||
{
|
||||
ctrl.Invoke(new Action(() =>
|
||||
{
|
||||
if (ctrl.Visible == visible && ctrl.Text == msg && ctrl.ForeColor == color) return;
|
||||
|
||||
ctrl.Visible = visible;
|
||||
ctrl.ForeColor = color;
|
||||
ctrl.Text = $@"{msg}";
|
||||
ctrl.Update();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctrl.Visible == visible && ctrl.Text == msg && ctrl.ForeColor == color) return;
|
||||
|
||||
ctrl.Visible = visible;
|
||||
ctrl.ForeColor = color;
|
||||
ctrl.Text = $@"{msg}";
|
||||
ctrl.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user