ControlsUtils.SetControlPropertyThreadSafeDelegate: Method to change properties of controls in a thread safe way.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Windows.Forms;
|
using System.Reflection;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace VAR.Toolbox.Controls
|
namespace VAR.Toolbox.Controls
|
||||||
{
|
{
|
||||||
@@ -8,5 +9,32 @@ namespace VAR.Toolbox.Controls
|
|||||||
{
|
{
|
||||||
return size * 96f / ctrl.CreateGraphics().DpiX;
|
return size * 96f / ctrl.CreateGraphics().DpiX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private delegate void SetControlPropertyThreadSafeDelegate(
|
||||||
|
Control control,
|
||||||
|
string propertyName,
|
||||||
|
object propertyValue);
|
||||||
|
|
||||||
|
public static void SetControlPropertyThreadSafe(
|
||||||
|
Control control,
|
||||||
|
string propertyName,
|
||||||
|
object propertyValue)
|
||||||
|
{
|
||||||
|
if (control.InvokeRequired)
|
||||||
|
{
|
||||||
|
control.Invoke(new SetControlPropertyThreadSafeDelegate
|
||||||
|
(SetControlPropertyThreadSafe),
|
||||||
|
new object[] { control, propertyName, propertyValue });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
control.GetType().InvokeMember(
|
||||||
|
propertyName,
|
||||||
|
BindingFlags.SetProperty,
|
||||||
|
null,
|
||||||
|
control,
|
||||||
|
new object[] { propertyValue });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user