当前位置: 首页>>代码示例>>C#>>正文


C# Button.Invoke方法代码示例

本文整理汇总了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;
     });
 }
开发者ID:niobos,项目名称:BBox3SagemTool,代码行数:12,代码来源:ThreadUtils.cs

示例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;
     });
 }
开发者ID:niobos,项目名称:BBox3SagemTool,代码行数:12,代码来源:ThreadUtils.cs

示例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;
     }
 }
开发者ID:riguelbf,项目名称:portalSureg,代码行数:12,代码来源:CrossThread.cs

示例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;
     }
 }
开发者ID:angieduan,项目名称:wowmultiplay,代码行数:16,代码来源:Helper_Thread.cs

示例5: SetText

        public static void SetText(Button button, string text)
        {
            MethodInvoker miSetText = delegate
            {
                button.Text = text;
            };

            if (button.InvokeRequired)
            {
                button.Invoke(miSetText);
            }
            else
            {
                miSetText();
            }
        }
开发者ID:NielsMinnee,项目名称:XrmToolBox,代码行数:16,代码来源:ButtonDelegates.cs

示例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;
     }
 }
开发者ID:souryavaranasi,项目名称:launch-tower,代码行数:16,代码来源:Form1.cs

示例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;
         }
     }
 }
开发者ID:san90279,项目名称:UK_OAS,代码行数:18,代码来源:frmSetUp.cs

示例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;
 }
开发者ID:narugo,项目名称:SteamGrouper,代码行数:14,代码来源:Interface.cs

示例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();
        }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:68,代码来源:MainForm.cs

示例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;

            }
        }
开发者ID:pratech,项目名称:USBRelayTester,代码行数:14,代码来源:USBRElayTester.cs

示例11: setButtonEnable

 private void setButtonEnable(Button button, bool enable)
 {
     if (button.InvokeRequired)
         button.Invoke(new Action(() => button.Enabled = enable));
     else
         button.Enabled = enable;
 }
开发者ID:aaasoft,项目名称:Quick.OwinMVC,代码行数:7,代码来源:ServiceButtons.cs

示例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); });

//.........这里部分代码省略.........
开发者ID:Rauul,项目名称:Stock-Car-Extreme-Launcher-3,代码行数:101,代码来源:Form1.cs

示例13: safeSetText

 private static void safeSetText(Button b, string s)
 {
     if (b.InvokeRequired)
     {
         b.Invoke(new Action(() => b.Text = s));
     }
     else
     {
         b.Text = s;
     }
 }
开发者ID:shtonki,项目名称:cardstone,代码行数:11,代码来源:PlayerPanel.cs

示例14: EnableButton

 private void EnableButton(Button b, bool f)
 {
     if (b.InvokeRequired)
         b.Invoke(new Action(() =>
             b.Enabled = f));
     else b.Enabled = f;
 }
开发者ID:molec1,项目名称:MySPM_NewParsers,代码行数:7,代码来源:Form1.cs

示例15: Disable

 private void Disable(Button button)
 {
     if (button.InvokeRequired)
         button.Invoke(new DisableDelegate(Disable), button);
     else
         button.PerformClick();
 }
开发者ID:println,项目名称:AutoFire_Lineage-csharp,代码行数:7,代码来源:Form1.cs


注:本文中的System.Windows.Forms.Button.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。