C#winform Flowlayoutpanel [英] C# winform Flowlayoutpanel

查看:150
本文介绍了C#winform Flowlayoutpanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在winform中,我已经采用了1个flowlayout面板,因为我已经创建了6 * 20个动态按钮,但是我不得不采取特定的行文本框,我怎么能在每个文本框中调用该事件,无论我是否必须调用该事件只有一次,或者我必须打电话20次。





in winform i had taken 1 flowlayout panel in that i had created 6*20 dynamic buttons, however i got stuck in taking the specific row textbox's how can i call the event in that each textbox, whether i have to call the event only once, or i have to call for 20 times.


if (!string.IsNullOrEmpty(txtbox1.Text))
          {
              for (int i = 0; i < num; i++)
              {
                  txtserial = new TextBox();
                  txtCode = new TextBox();
                  txtProduct = new TextBox();
                  txtGrams = new TextBox();
                  txtQty = new TextBox();
                  txtRate = new TextBox();
                  txtAmt = new TextBox();

                  txtProduct.AutoCompleteSource = AutoCompleteSource.CustomSource;
                  txtProduct.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

                  txtserial.Width = 50;
                  txtCode.Width = 100;
                  txtProduct.Width = 200;
                  txtGrams.Width = 100;
                  txtQty.Width = 100;
                  txtRate.Width = 100;
                  txtAmt.Width = 100;

                  txtAmt.ReadOnly = true;

                  txtserial.Name = "txtserial" + i;
                  txtCode.Name = "txtCode" + i;
                  txtProduct.Name = "txtProduct" + i;
                  txtGrams.Name = "txtGrams" + i;
                  txtQty.Name = "txtQty" + i;
                  txtRate.Name = "txtRate" + i;
                  txtAmt.Name = "txtAmt" + i;
                  //if (i != 0)
                  //{
                  //    txtserial.Visible = false;
                  //    txtCode.Visible = false;
                  //    txtProduct.Visible = false;
                  //    txtGrams.Visible = false;
                  //    txtQty.Visible = false;
                  //    txtRate.Visible = false;
                  //    txtAmt.Visible = false;
                  //}


                  this.flowLayoutPanel1.Controls.Add(txtserial);
                  this.flowLayoutPanel1.Controls.Add(txtCode);
                  this.flowLayoutPanel1.Controls.Add(txtProduct);
                  this.flowLayoutPanel1.Controls.Add(txtGrams);
                  this.flowLayoutPanel1.Controls.Add(txtQty);
                  this.flowLayoutPanel1.Controls.Add(txtRate);
                  this.flowLayoutPanel1.Controls.Add(txtAmt);

                  txtQty.KeyPress += new KeyPressEventHandler(txtserial3_KeyPress);
                  txtRate.KeyPress += new KeyPressEventHandler(txtserial3_KeyPress);
                  txtAmt.KeyPress += new KeyPressEventHandler(txtserial3_KeyPress);
                  txtQty.TextChanged += new EventHandler(txtserial3_TextChanged);
                  txtRate.TextChanged += new EventHandler(txtserial3_TextChanged);
                  txtProduct.TextChanged += new EventHandler(txtserial2_TextChanged);
                  txtAmt.TextChanged += new EventHandler(txtserial6_TextChanged);
                  txtCode.KeyPress += new KeyPressEventHandler(txtserial1_KeyPress);

推荐答案

如果我理解你的话...... 循环 [ ^ ]通过表单上的按钮集合并动态添加事件处理程序;)



这是一个如何以编程方式添加事件处理程序的示例:活动教程(C#) [ ^ ]

逐步执行:C#中的事件处理 [ ^ ]

C#动态添加事件处理程序 [ ^ ]

Foreach Control in form,我该如何处理我表格中的所有TextBox? [ ^ ]
If i understand you well.. loop[^] through the collection of buttons on the form and add event handler dynamically ;)

Here is an example how to add event handler programmatically: Events tutorial (C#)[^]
Step by Step: Event handling in C#[^]
C# dynamically add event handler[^]
Foreach Control in form, how can I do something to all the TextBoxes in my Form?[^]


这篇关于C#winform Flowlayoutpanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆