本文整理汇总了C#中System.Windows.Forms.Control.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Invoke方法的具体用法?C# Control.Invoke怎么用?C# Control.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetControlPropertyThreadSafe
public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
{
if (control == null)
{
throw new ArgumentNullException("control");
}
if (control.InvokeRequired)
{
if (control.IsHandleCreated)
{
try
{
control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
}
catch { }
}
}
else
{
if (!control.IsDisposed)
{
try
{
control.GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control, new object[] { propertyValue });
}
catch { }
}
}
}
示例2: SetControlPropertyThreadSafe
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, System.Reflection.BindingFlags.SetProperty, null, control,
new object[] { propertyValue });
}
示例3: add_text
public static void add_text(Control c, object s)
{
if (c.InvokeRequired)
c.Invoke(new Action<Control, object>(add_text), new object[] { c, s });
else
c.Text += s.ToString();
}
示例4: Get
public static object Get(Control control, object noncontrol, string propertyName)
{
if (control != null && !string.IsNullOrEmpty(propertyName))
if (control.InvokeRequired)
return control.Invoke(new PropertyGetInvoker(Get),
control,
noncontrol,
propertyName
);
else
{
PropertyInfo pi = GetPropertyInfo(control, noncontrol, propertyName);
object invokee = (noncontrol == null) ? control : noncontrol;
if (pi != null)
if (pi.CanRead)
return pi.GetValue(invokee, null);
else
throw new Exception(
string.Format(
"{0}.{1} is a write-only property.",
invokee.GetType().ToString(),
propertyName
));
return null;
}
else
throw new ArgumentNullException("Invalid argument.");
}
示例5: SetText
public static void SetText(Control control, string text)
{
if (control.InvokeRequired)
control.Invoke(new SetTextDelegate(SetText), control, text);
else
control.Text = text;
}
示例6: SetEnabled
public static void SetEnabled(Control control, bool value)
{
if (control.InvokeRequired)
control.Invoke(new SetEnabledDelegate(SetEnabled), control, value);
else
control.Enabled = value;
}
示例7: ResetText
public static void ResetText(Control control)
{
if (control.InvokeRequired)
control.Invoke(new ResetTextDelegate(ResetText), control);
else
control.ResetText();
}
示例8: Hide
public static void Hide(Control control)
{
if (control.InvokeRequired)
control.Invoke(new ShowHideDelegate(Hide), control);
else
control.Hide();
}
示例9: InvokeOnUiThread
public void InvokeOnUiThread(Control control, Action<Control> action)
{
if(control.InvokeRequired)
{
control.Invoke(action);
}
}
示例10: InvokeIfRequired
public static void InvokeIfRequired(Control c, VoidDelegate d)
{
if (c.InvokeRequired)
c.Invoke(d);
else
d.Invoke();
}
示例11: GetPropertyValue
/// <summary>
/// Get a property value on the control thread-safely.
/// </summary>
/// <param name="control">Control on which to GET the property value</param>
/// <param name="propertyName">Property name</param>
/// <return>Property value</return>
public static object GetPropertyValue(Control control, string propertyName)
{
if (control != null && !string.IsNullOrEmpty(propertyName))
{
if (control.InvokeRequired)
{
return control.Invoke(new PropertyGetInvoker(GetPropertyValue),
control, propertyName);
}
else
{
PropertyInfo propertyInfo = GetProperty(control, propertyName);
if (propertyInfo != null)
{
if (propertyInfo.CanRead)
{
return propertyInfo.GetValue(control, null);
}
else
{
throw new Exception(control.GetType().ToString() + "." + propertyName +
" is write-only property.");
}
}
return null;
}
}
else
{
throw new ArgumentNullException();
}
}
示例12: GetControlOwnerThread
private Thread GetControlOwnerThread(Control ctrl)
{
if (ctrl.InvokeRequired)
return (Thread)ctrl.Invoke(new Func<Thread>(() => GetControlOwnerThread(ctrl)));
else
return System.Threading.Thread.CurrentThread;
}
示例13: InvokeIfNecessary
public static void InvokeIfNecessary(Control control, MethodInvoker action)
{
if (control.InvokeRequired)
control.Invoke(action);
else
action();
}
示例14: EnableControl
private void EnableControl(Control control)
{
control.Invoke(new Action(() =>
{
control.Enabled = true;
}));
}
示例15: ControlInvokeRequired
/// <summary>
/// Helper method to determin if invoke required, if so will rerun method on correct thread.
/// if not do nothing. From: http://stackoverflow.com/a/26506378/457880
/// </summary>
/// <param name="c">Control that might require invoking</param>
/// <param name="a">action to preform on control thread if so.</param>
/// <returns>true if invoke required</returns>
public bool ControlInvokeRequired(Control c, Action a)
{
if (c.InvokeRequired) c.Invoke(new MethodInvoker(delegate { a(); }));
else return false;
return true;
}