我正在.NET窗口应用程序上工作. [英] I am doing work on .NET window application.
问题描述
我的问题是使用按钮将两个数字相加的代码是什么?
我尝试过的事情:
代码在这里类
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
命名空间WindowsFormsApplication4
{
类Class1
{
int a;
int b;
int sum;
public void main()
{
a = 5;
b = 6;
sum = a + b;
MessageBox.Show(总和为=" + sum.ToString());
}
}
}
我需要按钮代码,请告诉我按钮代码..?
my question is that what is the code to add two numbers using button?
What I have tried:
code is here of class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
class Class1
{
int a;
int b;
int sum;
public void main()
{
a = 5;
b = 6;
sum= a + b;
MessageBox.Show("the sum is="+sum.ToString());
}
}
}
and i need button code please tell me button code..?
推荐答案
先阅读这些文档
Windows窗体-文本框控件 [ Windows窗体-按钮控件 [ ^ ]
Read these docs first
Windows Form - TextBox Control[^]
Windows Form - Button Control[^]
private void btnAdd_Click(object sender, EventArgs e)
{
/*
* add two controls in the form and rename the 'name' property as txtA and txtB
* add a button control and rename it to btnAdd, then double click the button, visual studio IDE wll add this event code for you
* and you add your logic in this code block as below.
*/
int a = Convert.ToInt32(txtA.Text.Trim()); // convert to int .. explore int.TryParse for validation
int b = Convert.ToInt32(txtB.Text.Trim()); // convert to int .. explore int.TryParse for validation
int sum = a + b;
MessageBox.Show("the sum is=" + sum.ToString());
}
没有Windows窗体类.您应该创建新的Windows窗体应用程序.您会看到一个表格. Visual Studio左侧有工具箱,请看那里.工具箱包含文本框,按钮等.您必须拖放两个文本框和一个按钮.并双击按钮.现在,您可以查看后面的代码.您可以使用F7键切换到设计器/编码器屏幕.
There is no windows form class. You should create new Windows Forms Application. You see a form. Visual studio have left side Toolbox, look at there. Toolbox contains textbox, button etc. You have to drag and drop two textbox and a button. And double click the button. Now you view code behind. You use F7 key for switch to designer/coder screen.
这篇关于我正在.NET窗口应用程序上工作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!