本文整理汇总了C#中System.Windows.Forms.Form.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Form.Invoke方法的具体用法?C# Form.Invoke怎么用?C# Form.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Form
的用法示例。
在下文中一共展示了Form.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override void Run(ServiceController[] services, Form mainForm, DataGrid serviceGrid)
{
var addedMachine = QuickDialog2.DoQuickDialog("Add A Machine's Services", "Machine Name:",".","Pattern ^(Enable|EPX):","");
if (addedMachine != null)
{
MachineName = addedMachine[0];
this.SearchPattern = addedMachine[1];
try
{
DataGrid dgrid = serviceGrid;
this.addView = (DataView)dgrid.DataSource;
CurrencyManager bm = (CurrencyManager)dgrid.BindingContext[this.addView];
ArrayList arrSelectedRows = new ArrayList();
this.addView = (DataView)bm.List;
mainForm.Invoke(new InvokeDelegate(this.AddMachineInGUIThread));
serviceGrid.Refresh();
}
finally
{
addedMachine = null;
addView = null;
}
}
}
示例2: MainWindow
public MainWindow(Form parent, OGameBot bot, UGInfos forumInfos)
{
_bot = bot;
_parent = parent;
InitializeComponent();
forumUserLabel.Text = @"User: " + forumInfos.User;
forumUIDLabel.Text = @"Post: " + forumInfos.Post;
forumPostLabel.Text = @"UID: " + forumInfos.UID;
forumStatusLabel.Text = @"Status: " + forumInfos.Status;
PopulateAddBuildingList();
_bot.BeganBuild += (o, b) => DisplayLogMessage(@"Iniziata la costruzione di " + b.GetDescription());
_bot.Built += (o, b) =>
{
DisplayLogMessage(@"Terminata la costruzione di " + b.GetDescription());
buildingListView.Invoke(new Action(() => buildingListView.Items.RemoveAt(0)));
};
_bot.BuildingUnavaiable += (o, b) => DisplayLogMessage(@"Non puoi costruire " + b.GetDescription() + ", verrà spostato in fondo alla coda.");
_bot.NotEnoughResources += (o, b) =>
{
if (_notEnoughResourcesCount == 0)
DisplayLogMessage(@"Risorse non sufficenti per " + b.GetDescription() +
", in attesa");
_notEnoughResourcesCount = ++_notEnoughResourcesCount%20;
};
_bot.InConstruction += o =>
{
if (_inConstructionCount == 0)
DisplayLogMessage(
@"E' già presente un edificio in costruzione, in attesa");
_inConstructionCount = ++_inConstructionCount%20;
};
_bot.Stopped += o => _parent.Invoke(new Action(Close));
}
示例3: Close
public static void Close(Form form)
{
if (form.InvokeRequired)
form.Invoke(new CloseDelegate(Close), form);
else
form.Close();
}
示例4: GetDetails
/// <summary>
/// Will open a form that will ask for connection details (with option for default props) and attempt to ping target to see if it is possible to establish connection
/// </summary>
/// <param name="parent">Parent form that this form will be opened on</param>
/// <param name="default_details">The default connection details to be inserted</param>
/// <param name="forceTesting"></param>
public static ConnectionDetails GetDetails(Form parent, ConnectionDetails default_details, bool forceTesting = true) {
UserConnectionDetailsRequester getter = null;
parent.Invoke(() => {
getter = new UserConnectionDetailsRequester(forceTesting, default_details);
getter.ShowDialog(parent);
});
return getter.Results();
}
示例5: UIActor
/// <summary>
/// Default constructor.
/// </summary>
/// <param name="mainApplicationForm">The application's main form</param>
public UIActor(Form mainApplicationForm)
{
m_applicationForm = mainApplicationForm;
m_applicationForm.Invoke((Action)(() =>
{
if (Actor.CurrentActor != null) Actor.CurrentActor = this;
}));
}
示例6: ShowErrorCallback
private delegate void ShowErrorCallback(Form frmWindow, string strMessage, Exception objException); // Permite llamadas asíncronas para mostrar un mensaje
/// <summary>
/// Muestra un cuadro de mensaje
/// </summary>
public static void ShowMessage(Form frmWindow, string strMessage)
{ // InvokeRequired compara el ID del hilo llamante con el ID del hilo creador, si son diferentes devuelve True
if (frmWindow != null && frmWindow.InvokeRequired)
{ ShowMessageCallback fncCallback = new ShowMessageCallback(ShowMessage);
frmWindow.Invoke(fncCallback, new object[] { frmWindow, strMessage });
}
else
MessageBox.Show(frmWindow, strMessage, Application.ProductName);
}
示例7: DrawingSystem
public DrawingSystem(Form form, EntityManager manager)
: base(manager)
{
_form = form;
_form.Invoke(new Action(() =>
{
_context = BufferedGraphicsManager.Current;
_buffer = _context.Allocate(_form.CreateGraphics(), _form.DisplayRectangle);
}));
}
示例8: CloseForm
public static void CloseForm(Form form)
{
// Check if the form need to be invoked.
if (form.InvokeRequired)
// Invoke the form with the appropiate delegate.
form.Invoke(new Action<Form>(CloseForm), form);
else
// Directly close the form.
form.Close();
}
示例9: Invoke
public static void Invoke(Form form, AsyncAction action)
{
if (!form.InvokeRequired)
{
action();
}
else
{
form.Invoke((DispatcherInvoker)Invoke, form, action);
}
}
示例10: SetText
public static void SetText(Form form, Control ctrl, string text)
{
if (ctrl.InvokeRequired)
{
SetTextCallback stc = SetText;
form.Invoke(stc, new object[] {form, ctrl, text});
}
else
{
ctrl.Text = text;
}
}
示例11: GameWindow
/// <summary>
/// Initializes a new GameWindow class.
/// </summary>
/// <param name="handle">The Handle.</param>
internal GameWindow(IntPtr handle)
{
_surface = (Form) Control.FromHandle(handle);
_surfaceStyle = SurfaceStyle.Normal;
_surfaceLayout = new SurfaceLayout(true, false, true);
CursorVisibility = false;
_surface.FormClosing += _surface_FormClosing;
_surface.Activated += _surface_Activated;
_surface.Deactivate += _surface_Deactivate;
MethodInvoker br = delegate { _surface.KeyPreview = true; };
_surface.Invoke(br);
}
示例12: SafeGetWindowHandle
/// <summary>
/// Safely retrieves the window's handle. The events the InstanceManager are on a separate thread
/// forcing us to marshall the calls back to the window's thread.
/// </summary>
/// <param name="window">The window to retrieve the handle for.</param>
/// <returns></returns>
public static IntPtr SafeGetWindowHandle(Form window)
{
if (window == null)
{
return IntPtr.Zero;
}
if (window.InvokeRequired)
{
return (IntPtr)window.Invoke(new GetWindowHandleDelegate(SafeGetWindowHandle), window);
}
return window.Handle;
}
示例13: ActivateParentForm
private static void ActivateParentForm(Form parentForm)
{
if (parentForm != null)
{
//HandleRef href = new HandleRef(ParentForm, ParentForm.Handle);
//SetForegroundWindow(href);
parentForm.Invoke(new Action(() => { parentForm.Activate(); }));
}
else if (ApplicationService.Current.MainForm != null)
{
ApplicationService.Current.MainForm.Invoke(new Action(() => { ApplicationService.Current.MainForm.Activate(); }));
}
}
示例14: PrintText
public void PrintText(string txt, TextBox printBox, Form owner)
{
if (printBox.InvokeRequired)
{
invokeTextBox d = new invokeTextBox(PrintText);
owner.Invoke(d, txt, printBox, owner);
}
else
{
printBox.Text += txt;
printBox.Select(printBox.Text.Length, 0);
printBox.ScrollToCaret();
}
}
示例15: SetControlText
public static void SetControlText(this Control control, Form CFrom, string text)
{
if (CFrom.InvokeRequired)
{
ControlTextMethod controlTextMethod = SetControlText;
CFrom.Invoke(controlTextMethod, new object[] { control, CFrom, text });
}
else
{
control.Text = text;
}
Application.DoEvents();
}