按表单C#增加每个按钮点击表单的数量 [英] Increment number per button click form by form C#
本文介绍了按表单C#增加每个按钮点击表单的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这适用于排队系统。当单击下一个按钮(form1)时,必须处理增量编号文本框格式为2.
我尝试过:
//只能以同样的形式试用
this is for a queuing system. When the next button is clicked (form1) the increment number must be processed textbox which is in form 2.
What I have tried:
//only tried in same form
namespace Queuing_System
{
public partial class Counter1 : Form
{
int count = 0;
public Counter1()
{
InitializeComponent();
}
private void btnNext1_Click(object sender, EventArgs e)
{
count++;
textBox.Text = count.ToString();
}
}
}
推荐答案
在表格之间传递值c#windows application
,你会发现很多方法可以达到这个目的,
前两个结果从上面
在表格之间传递数据 [ ^ ]
传递数据c#窗体 [ ^ ]
示例:(这是其中一种方法)
google "passing values between forms c# windows application
" , you will find lot of ways to achieve this,
first two results from the above
Passing Data Between Forms[^]
Passing data c# windows form[^]
example: ( this is one of the method)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int count = 0;
Form2 objForm2 = new Form2();
private void btnNext1_Click_1(object sender, EventArgs e)
{
count++;
objForm2.textBox1.Text = count.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
objForm2.Show(); // show the form in form load or any other event, before incrementing the counter
}
}
Form2
将文本框的Access修饰符从 Private
更改为 Public
选择Form2 - >设计视图 - >点击文字框 - >右键单击 - >属性 - >找到Modifier属性 - >从私人变为公共。
In Form2
change the Access modifier of the textbox from Private
to Public
Select Form2 -> Design View -> Click the Textbox -> right click -> properties -> find the Modifier property -> Change from Private to Public.
这篇关于按表单C#增加每个按钮点击表单的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文