本文整理汇总了C#中System.Windows.Forms.Button.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Button.Invoke方法的具体用法?C# Button.Invoke怎么用?C# Button.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Button
的用法示例。
在下文中一共展示了Button.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setButtonTextFromThread
/// <summary>
/// Set button text from within a thread
/// </summary>
/// <param name="button">Button</param>
/// <param name="text">Button text</param>
public static void setButtonTextFromThread(Button button, string text)
{
button.Invoke((MethodInvoker)delegate
{
button.Text = text;
});
}
示例2: setButtonEnabledFromThread
/// <summary>
/// Set button enabled or disabled from within a thread
/// </summary>
/// <param name="button">Button</param>
/// <param name="enabled">Enabled or not</param>
public static void setButtonEnabledFromThread(Button button, bool enabled)
{
button.Invoke((MethodInvoker)delegate
{
button.Enabled = enabled;
});
}
示例3: EnableDisableButton
public static void EnableDisableButton(Button button, bool enabled)
{
if (button.InvokeRequired)
{
EnableDisableButtonDelegate button2 = new EnableDisableButtonDelegate(EnableDisableButton);
button.Invoke(button2, new object[] { button, enabled });
}
else
{
button.Enabled = enabled;
}
}
示例4: SetButtonForeColor
public static void SetButtonForeColor(Button btn, Color color)
{
if (btn.InvokeRequired)
{
SetButtonForeColorCallback D = new SetButtonForeColorCallback(SetButtonForeColor);
try
{
btn.Invoke(D, new object[] { btn, color });
}
catch { }
}
else
{
btn.ForeColor = color;
}
}
示例5: SetText
public static void SetText(Button button, string text)
{
MethodInvoker miSetText = delegate
{
button.Text = text;
};
if (button.InvokeRequired)
{
button.Invoke(miSetText);
}
else
{
miSetText();
}
}
示例6: setButtonEnabled
public void setButtonEnabled(Button button, Boolean enabled, String text)
{
if (button.InvokeRequired)
{
try
{
button.Invoke(new SetButtonEnabledDelegate(setButtonEnabled), new Object[] { button, enabled, text });
}
catch { }
}
else
{
button.Enabled = enabled;
button.Text = text;
}
}
示例7: SetButtonEnabled
public void SetButtonEnabled(Button btn, bool enable)
{
if (!this.Disposing)
{
if (btn.InvokeRequired)
{
SetButtonEnabledMethod call = delegate(Button btnd, bool enabled)
{
btnd.Enabled = enabled;
};
btn.Invoke(call, new object[] { btn, enable });
}
else
{
btn.Enabled = enable;
}
}
}
示例8: UpdateButton
public static void UpdateButton(Button button, string text)
{
// If the current thread is not the UI thread, InvokeRequired will be true
if (button.InvokeRequired)
{
// If so, call Invoke, passing it a lambda expression which calls
// UpdateText with the same label and text, but on the UI thread instead.
button.Invoke((Action)(() => UpdateButton(button, text)));
return;
}
// If we're running on the UI thread, we'll get here, and can safely update
// the button's text.
button.Text = text;
}
示例9: MainForm_Load
private void MainForm_Load(object sender, EventArgs e)
{
var controlConfig = Entrance.Parameter.GetControlConfigFunc?.Invoke();
if (controlConfig == null
|| controlConfig.Length == 0)
return;
currentToolStripItemCollection = cmsMain.Items;
foreach (var keyValuePair in controlConfig)
{
var key = keyValuePair.Key;
var value = keyValuePair.Value;
if (value == null)
{
handleGroup(key);
}
else
{
Control control = null;
if (value is string)
{
control = new Label() { Text = (string)value };
}
else if (value is Action)
{
var action = (Action)value;
var btn = new Button() { Text = key };
btn.Click += (sender2, e2) =>
{
disableForm();
action();
enableForm();
};
control = btn;
addNotifyIconButton(btn);
}
else if (value is Button)
{
Button sourceButton = (Button)value;
var btn = new Button() { Text = key };
btn.Click += (sender2, e2) =>
{
disableForm();
sourceButton.PerformClick();
enableForm();
};
sourceButton.EnabledChanged += (sender2, e2) =>
{
if (btn.InvokeRequired)
btn.Invoke(new Action(() => btn.Enabled = sourceButton.Enabled));
else
btn.Enabled = sourceButton.Enabled;
};
btn.Enabled = sourceButton.Enabled;
control = btn;
addNotifyIconButton(btn);
}
else if (value is Control)
{
flpTools.Controls.Add(new Label() { Text = key, Width = 56 });
control = (Control)value;
}
flpTools.Controls.Add(control);
}
}
this.CenterToScreen();
}
示例10: ChangeButton
private void ChangeButton(Button button,string text)
{
if (button.InvokeRequired)
{
ChangeButtonDelegate del = new ChangeButtonDelegate(ChangeButton);
button.Invoke(del, button,text);
}
else
{
button.Text = text;
}
}
示例11: setButtonEnable
private void setButtonEnable(Button button, bool enable)
{
if (button.InvokeRequired)
button.Invoke(new Action(() => button.Enabled = enable));
else
button.Enabled = enable;
}
示例12: PopulateMods
// Populate mods panels
public void PopulateMods()
{
List<string> modTypes = new List<string>() { "cars", "tracks", "skins", "misc" };
foreach (string type in modTypes)
{
List<Mod> modList = new List<Mod>();
int mods = 0;
if (type == "cars")
{
modList = modCarList;
}
else if (type == "tracks")
{
modList = modTrackList;
}
else if (type == "skins")
{
modList = modSkinList;
}
else if (type == "misc")
{
modList = modMiscList;
}
foreach (Mod mod in modList)
{
Panel modPanel = new Panel();
modPanel.Size = new Size(860, 61);
modPanel.Location = new Point(0, 1 + (modPanel.Height - 1) * mods);
modPanel.BorderStyle = BorderStyle.FixedSingle;
if (type == "cars")
{
carsTabPage.Invoke((MethodInvoker)delegate { carsTabPage.Controls.Add(modPanel); });
modPanel.MouseHover += delegate { carsTabPage.Focus(); };
}
else if (type == "tracks")
{
tracksTabPage.Invoke((MethodInvoker)delegate { tracksTabPage.Controls.Add(modPanel); });
modPanel.MouseHover += delegate { tracksTabPage.Focus(); };
}
else if (type == "skins")
{
skinsTabPage.Invoke((MethodInvoker)delegate { skinsTabPage.Controls.Add(modPanel); });
modPanel.MouseHover += delegate { skinsTabPage.Focus(); };
}
else if (type == "misc")
{
skinsTabPage.Invoke((MethodInvoker)delegate { miscTabPage.Controls.Add(modPanel); });
modPanel.MouseHover += delegate { miscTabPage.Focus(); };
}
Label modNameLabel = new Label();
modNameLabel.Text = mod.name.ToUpper();
modNameLabel.ForeColor = Color.Black;
modNameLabel.Location = new Point(0, 0);
modNameLabel.Padding = new Padding(4, 10, 0, 0);
modNameLabel.AutoSize = true;
modNameLabel.Dock = DockStyle.Left;
modNameLabel.Font = new Font("Arimo", 12, FontStyle.Bold);
modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modNameLabel); });
Label modVersionLabel = new Label();
modVersionLabel.Text = mod.version;
modVersionLabel.ForeColor = Color.FromArgb(64, 64, 64);
modVersionLabel.Location = new Point(modNameLabel.Width, 0);
modVersionLabel.Padding = new Padding(4, 10, 0, 0);
modVersionLabel.AutoSize = true;
modVersionLabel.Font = new Font("Arimo", 12, FontStyle.Regular);
modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modVersionLabel); });
Label modAuthorLabel = new Label();
modAuthorLabel.Text = mod.author;
modAuthorLabel.ForeColor = Color.FromArgb(64, 64, 64);
modAuthorLabel.Location = new Point(5, modPanel.Height - 20);
modAuthorLabel.AutoSize = true;
modAuthorLabel.Font = new Font("DejaVu Sans Condensed", 8, FontStyle.Regular);
modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modAuthorLabel); });
Label modDateLabel = new Label();
modDateLabel.Text = mod.date;
modDateLabel.ForeColor = Color.FromArgb(64, 64, 64);
modDateLabel.Location = new Point(20 + modAuthorLabel.Width, modPanel.Height - 20);
modDateLabel.AutoSize = true;
modDateLabel.Font = new Font("DejaVu Sans Condensed", 8, FontStyle.Regular);
modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modDateLabel); });
Button modDownloadButton = new Button();
modDownloadButton.Size = new Size(100, 61);
modDownloadButton.ForeColor = Color.Black;
modDownloadButton.BackColor = Color.WhiteSmoke;
modDownloadButton.UseVisualStyleBackColor = true;
modDownloadButton.FlatStyle = FlatStyle.Flat;
//modDownloadButton.Dock = DockStyle.Right;
modDownloadButton.Location = new Point(759, -1);
modDownloadButton.Text = mod.size + " MB";
modDownloadButton.Font = new Font("DejaVu Sans Condensed", 10, FontStyle.Regular);
modPanel.Invoke((MethodInvoker)delegate { modPanel.Controls.Add(modDownloadButton); });
//.........这里部分代码省略.........
示例13: safeSetText
private static void safeSetText(Button b, string s)
{
if (b.InvokeRequired)
{
b.Invoke(new Action(() => b.Text = s));
}
else
{
b.Text = s;
}
}
示例14: EnableButton
private void EnableButton(Button b, bool f)
{
if (b.InvokeRequired)
b.Invoke(new Action(() =>
b.Enabled = f));
else b.Enabled = f;
}
示例15: Disable
private void Disable(Button button)
{
if (button.InvokeRequired)
button.Invoke(new DisableDelegate(Disable), button);
else
button.PerformClick();
}