本文整理汇总了C#中Control.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Invoke方法的具体用法?C# Control.Invoke怎么用?C# Control.Invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Control
的用法示例。
在下文中一共展示了Control.Invoke方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Snapshot
public static Bitmap Snapshot(Control c, int width = 0, int height = 0)
{
IntPtr hwnd = IntPtr.Zero;
IntPtr dc = IntPtr.Zero;
c.Invoke(new MethodInvoker(() =>
{
if (width == 0)
{
width = c.ClientSize.Width;
}
if (height == 0)
{
height = c.ClientSize.Height;
}
hwnd = c.Handle;
dc = GetDC(hwnd);
}));
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppRgb);
if (dc != IntPtr.Zero)
{
try
{
using (Graphics g = Graphics.FromImage(bmp))
{
IntPtr bdc = g.GetHdc();
try
{
BitBlt(bdc, 0, 0, width, height, dc, 0, 0, TernaryRasterOperations.SRCCOPY);
}
finally
{
g.ReleaseHdc(bdc);
}
}
}
finally
{
ReleaseDC(hwnd, dc);
}
}
return bmp;
}
示例2: SetControlText
/// <summary>
/// Sets the text for the specified control in multithreading circumstances.
/// </summary>
/// <param name="control"></param>
/// <param name="text"></param>
public static void SetControlText(Control control, String text)
{
if (control != null)
{
if (control.InvokeRequired)
{
SetControlTextSafe scts = new SetControlTextSafe(SetControlText);
control.Invoke(scts, new Object[] { control, text });
}
else
{
control.Text = text;
}
}
}
示例3: SetControlVisible
/// <summary>
/// Sets the text for the specified control in multithreading circumstances.
/// </summary>
/// <param name="control"></param>
/// <param name="text"></param>
public static void SetControlVisible(Control control, bool val)
{
if (control != null)
{
if (control.InvokeRequired)
{
SetControlVisibleSafe2 scts = new SetControlVisibleSafe2(SetControlVisible);
control.Invoke(scts, new Object[] { control, val });
}
else
{
control.Visible = val;
}
}
}
示例4: setControlTheme
public void setControlTheme(Control set_me, string to_me)
{
if(set_me.InvokeRequired) {
set_me.Invoke(new setControlThemeDelegate(setControlTheme), new Object[] { set_me, to_me});
} else {
lock(set_me) {
SetWindowTheme(set_me.Handle,to_me,null);
}
}
}