<small id='6MLDh'></small><noframes id='6MLDh'>

  • <tfoot id='6MLDh'></tfoot>
  • <legend id='6MLDh'><style id='6MLDh'><dir id='6MLDh'><q id='6MLDh'></q></dir></style></legend>
    • <bdo id='6MLDh'></bdo><ul id='6MLDh'></ul>
        <i id='6MLDh'><tr id='6MLDh'><dt id='6MLDh'><q id='6MLDh'><span id='6MLDh'><b id='6MLDh'><form id='6MLDh'><ins id='6MLDh'></ins><ul id='6MLDh'></ul><sub id='6MLDh'></sub></form><legend id='6MLDh'></legend><bdo id='6MLDh'><pre id='6MLDh'><center id='6MLDh'></center></pre></bdo></b><th id='6MLDh'></th></span></q></dt></tr></i><div id='6MLDh'><tfoot id='6MLDh'></tfoot><dl id='6MLDh'><fieldset id='6MLDh'></fieldset></dl></div>

        C# - 使用代码添加按钮单击事件

        C# - Add button click events using code(C# - 使用代码添加按钮单击事件)

          • <tfoot id='wVJjZ'></tfoot>
              <tbody id='wVJjZ'></tbody>
            <legend id='wVJjZ'><style id='wVJjZ'><dir id='wVJjZ'><q id='wVJjZ'></q></dir></style></legend>

              <small id='wVJjZ'></small><noframes id='wVJjZ'>

                <bdo id='wVJjZ'></bdo><ul id='wVJjZ'></ul>

              • <i id='wVJjZ'><tr id='wVJjZ'><dt id='wVJjZ'><q id='wVJjZ'><span id='wVJjZ'><b id='wVJjZ'><form id='wVJjZ'><ins id='wVJjZ'></ins><ul id='wVJjZ'></ul><sub id='wVJjZ'></sub></form><legend id='wVJjZ'></legend><bdo id='wVJjZ'><pre id='wVJjZ'><center id='wVJjZ'></center></pre></bdo></b><th id='wVJjZ'></th></span></q></dt></tr></i><div id='wVJjZ'><tfoot id='wVJjZ'></tfoot><dl id='wVJjZ'><fieldset id='wVJjZ'></fieldset></dl></div>

                  本文介绍了C# - 使用代码添加按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 C# 和编程方面的经验几乎为零,所以你可能会觉得我的问题很愚蠢.但是,我尝试使用代码创建一个 Windows 窗体,并且我已经成功实现了我想要的.但现在我想为我的所有按钮添加按钮点击事件.我希望 addToDay[i] 清除 exerciseBox[i]、setBox[i] 和 repBox[i] 中的文本.谢谢.

                  I have almost 0 experience with C# and programming overall, so you might find my question stupid. However, Im trying to create a Windows Form using code and I've succeeded with what I've wanted. But now I would like to add button click events to all my buttons. I want addToDay[i] to clear text in exerciseBox[i], setBox[i] and repBox[i]. Thanks.

                      public NewSchedule2(string path)
                      {
                          InitializeComponent();
                          this.SuspendLayout();
                  
                          labels = new System.Windows.Forms.Label[7];
                          exercises = new System.Windows.Forms.TextBox[7];
                          sets = new System.Windows.Forms.TextBox[7];
                          reps = new System.Windows.Forms.TextBox[7];
                          addToDay = new System.Windows.Forms.Button[7];
                  
                          string[] lines = File.ReadAllLines(path);
                  
                          for (int i = 0; i < 7; i++)
                          {
                              this.labels[i] = new System.Windows.Forms.Label();
                              this.labels[i].Location = new System.Drawing.Point(40, 40 + i * 50);
                              this.labels[i].Name = "Label" + i;
                              this.labels[i].Size = new System.Drawing.Size(110, 20);
                              this.labels[i].Text = lines[i];
                              this.Controls.Add(this.labels[i]);
                  
                              if (lines[i] == "Restday")
                              {
                  
                              }
                              else
                              {
                                  this.exercises[i] = new System.Windows.Forms.TextBox();
                                  this.exercises[i].Location = new System.Drawing.Point(160, 40 + i * 50);
                                  this.exercises[i].Name = "excersiceBox" + i;
                                  this.exercises[i].Size = new System.Drawing.Size(110, 20);
                                  this.exercises[i].Text = "";
                                  this.Controls.Add(this.exercises[i]);
                  
                                  this.sets[i] = new System.Windows.Forms.TextBox();
                                  this.sets[i].Location = new System.Drawing.Point(290, 40 + i * 50);
                                  this.sets[i].Name = "setBox" + i;
                                  this.sets[i].Size = new System.Drawing.Size(40, 20);
                                  this.sets[i].Text = "";
                                  this.Controls.Add(this.sets[i]);
                  
                                  this.reps[i] = new System.Windows.Forms.TextBox();
                                  this.reps[i].Location = new System.Drawing.Point(350, 40 + i * 50);
                                  this.reps[i].Name = "repBox" + i;
                                  this.reps[i].Size = new System.Drawing.Size(40, 20);
                                  this.reps[i].Text = "";
                                  this.Controls.Add(this.reps[i]);
                  
                                  this.addToDay[i] = new System.Windows.Forms.Button();
                                  this.addToDay[i].Location = new System.Drawing.Point(430, 40 + i * 50);
                                  this.addToDay[i].Name = "addToDay" + i;
                                  this.addToDay[i].Click += new System.EventHandler(this.button_Clicked);
                                  this.addToDay[i].Size = new System.Drawing.Size(80, 20);
                                  this.addToDay[i].Text = "Add To " + lines[i];
                                  this.Controls.Add(this.addToDay[i]);
                              }
                          }
                      }
                  
                      private void button_Clicked(object sender, EventArgs e)
                      {
                  
                      }
                  }
                  

                  推荐答案

                  这是一个示例,您可以使用这些示例来完成此任务.祝你学习愉快:)

                  Here is it a sample of what you could use in order to accomplish that. I wish you an happy learning :)

                     public NewSchedule2(string path)
                      {
                          InitializeComponent();
                          this.SuspendLayout();
                  
                          labels = new System.Windows.Forms.Label[7];
                          exercises = new System.Windows.Forms.TextBox[7];
                          sets = new System.Windows.Forms.TextBox[7];
                          reps = new System.Windows.Forms.TextBox[7];
                          addToDay = new System.Windows.Forms.Button[7];
                  
                          string[] lines = File.ReadAllLines(path);
                  
                          for (int i = 0; i < 7; i++)
                          {
                              this.labels[i] = new System.Windows.Forms.Label();
                              this.labels[i].Location = new System.Drawing.Point(40, 40 + i * 50);
                              this.labels[i].Name = "Label" + i;
                              this.labels[i].Size = new System.Drawing.Size(110, 20);
                              this.labels[i].Text = lines[i];
                              this.Controls.Add(this.labels[i]);
                  
                              if (lines[i] == "Restday")
                              {
                  
                              }
                              else
                              {
                                  this.exercises[i] = new System.Windows.Forms.TextBox();
                                  this.exercises[i].Location = new System.Drawing.Point(160, 40 + i * 50);
                                  this.exercises[i].Name = "excersiceBox" + i;
                                  this.exercises[i].Size = new System.Drawing.Size(110, 20);
                                  this.exercises[i].Text = "";
                                  this.Controls.Add(this.exercises[i]);
                  
                                  this.sets[i] = new System.Windows.Forms.TextBox();
                                  this.sets[i].Location = new System.Drawing.Point(290, 40 + i * 50);
                                  this.sets[i].Name = "setBox" + i;
                                  this.sets[i].Size = new System.Drawing.Size(40, 20);
                                  this.sets[i].Text = "";
                                  this.Controls.Add(this.sets[i]);
                  
                                  this.reps[i] = new System.Windows.Forms.TextBox();
                                  this.reps[i].Location = new System.Drawing.Point(350, 40 + i * 50);
                                  this.reps[i].Name = "repBox" + i;
                                  this.reps[i].Size = new System.Drawing.Size(40, 20);
                                  this.reps[i].Text = "";
                                  this.Controls.Add(this.reps[i]);
                  
                                  this.addToDay[i] = new System.Windows.Forms.Button();
                                  this.addToDay[i].Location = new System.Drawing.Point(430, 40 + i * 50);
                                  this.addToDay[i].Name = "addToDay" + i;
                                  this.addToDay[i].Click += new System.EventHandler(this.button_Clicked);
                                  this.addToDay[i].Size = new System.Drawing.Size(80, 20);
                                  this.addToDay[i].Text = "Add To " + lines[i];
                                  this.addToDay[i].Click += new System.EventHandler(this.button_Clicked);
                                  this.Controls.Add(this.addToDay[i]);
                              }
                          }
                      }
                  
                     private void button_Clicked(object sender, EventArgs e)
                      {
                          Button triggeredButton = (Button) sender;
                  
                          var numAlpha = new Regex("(?<Alpha>[a-zA-Z]*[ _]?)(?<Numeric>[0-9]*)");
                          var match = numAlpha.Match(triggeredButton.Name);
                          var num = match.Groups["Numeric"].Value;
                  
                          this.exercises[num].Text = string.Empty;
                          this.sets[num].Text = string.Empty;
                          this.reps[num].Text = string.Empty;
                      }
                  

                  这篇关于C# - 使用代码添加按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                  Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                  Multi-color TextBox C#(多色文本框 C#)
                  How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                  C# Numeric Only TextBox Control(C# 纯数字文本框控件)
                  Unicode characters not showing in System.Windows.Forms.TextBox(System.Windows.Forms.TextBox 中未显示 Unicode 字符)

                      <tbody id='MYl9F'></tbody>

                    <i id='MYl9F'><tr id='MYl9F'><dt id='MYl9F'><q id='MYl9F'><span id='MYl9F'><b id='MYl9F'><form id='MYl9F'><ins id='MYl9F'></ins><ul id='MYl9F'></ul><sub id='MYl9F'></sub></form><legend id='MYl9F'></legend><bdo id='MYl9F'><pre id='MYl9F'><center id='MYl9F'></center></pre></bdo></b><th id='MYl9F'></th></span></q></dt></tr></i><div id='MYl9F'><tfoot id='MYl9F'></tfoot><dl id='MYl9F'><fieldset id='MYl9F'></fieldset></dl></div>

                      <small id='MYl9F'></small><noframes id='MYl9F'>

                      • <bdo id='MYl9F'></bdo><ul id='MYl9F'></ul>
                        <legend id='MYl9F'><style id='MYl9F'><dir id='MYl9F'><q id='MYl9F'></q></dir></style></legend>
                        1. <tfoot id='MYl9F'></tfoot>