我如何在Windows应用程序上进行计算 [英] how do i do a calculation on a windows application

查看:44
本文介绍了我如何在Windows应用程序上进行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在创建一个Windows应用程序,显示名称的出生日期和从出生日期到特定目标日期的心跳数.我的程序显示了姓名和出生日期,但我无法让该程序进行计算.我已经在顶部将变量声明为每天的节拍和每周的节拍等,我想知道是否有人可以按输入按钮后如何让我的程序来计算所有这些值?这是我的代码,非常感谢

 使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用使用System.Drawing;
使用 System.Linq;
使用 System.Text;
使用使用System.Windows.Forms;
命名空间第3季度
{
    公共 部分  class  Form1:表单
    {
         int  bpd;
         int  bpw;
         int  bpm;
         int  bpy;
         int  bted;
         int  enb;
        公共 Form1()
        {
            InitializeComponent();
        }
        私有 无效 btnenter_Click(对象发​​件人,EventArgs e)
        {
            bpd =  70  *  23 ;
            bpw =  1680  *  5 ;
            bpm =  11760  *  6 ;
            bpy =  47040  *  13 ;
            bted =  564480  *  39 ;
            enb =  22456560  +  16800 ;

        }

        私有 无效 txtheartbeats_TextChanged(对象发​​件人,EventArgs e)
        {
            txtheartbeats.Text = " ;
        }
        私有 无效 txtname_TextChanged(对象发​​件人,EventArgs e)
        {
            txtname.Text = " ;
        }
        私有 无效 txtDob_TextChanged(对象发​​件人,EventArgs e)
        {
            txtDob.Text = " ;
        }
        私有 无效 txtTargetdate_TextChanged(对象发​​件人,EventArgs e)
        {
            txtTargetdate.Text = " ;
        }

    }
} 

解决方案

将DOB存储为DateTime-然后可以从目标DateTime中减去它,以提供TimeSpan [)也无济于事.它会取消在文本框中输入的所有内容.您可能需要一周使用标签.


在这种情况下(将来,请修改您的问题而不是回答自己),您需要处理Button.Click事件,而不是textbox.TextChanged事件.您将在现有代码中做的所有事情都是循环进行:
txtTargetdate_TextChanged事件设置txtTargetdate的文本->导致txtTargetdate_TextChanged事件,该事件设置....
的文本
而是在单个myButton_Click事件中设置textbox.Text值,然后从所有文本框中删除TextChanged事件处理程序.


Hi,
I am creating a windows application showing name date of birth and number of heartbeats from date of birth to a particular targetdate. My program is showing name and date of birth but i cannot get the program to work out the calculations. i have declared the variables at the top as beats per day and beats per week etc, i was wondering if anyone can help me as on how to get the program to calculate all these values once the enter button is pressed? here is my code, many thanks

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace q3
{
    public partial class Form1 : Form
    {
        int bpd;
        int bpw;
        int bpm;
        int bpy;
        int bted;
        int enb;
        public Form1()
        {
            InitializeComponent();
        }
        private void btnenter_Click(object sender, EventArgs e)
        {
            bpd = 70 * 23;
            bpw = 1680 * 5;
            bpm = 11760 * 6;
            bpy = 47040 * 13;
            bted = 564480 * 39;
            enb = 22456560 + 16800;

        }

        private void txtheartbeats_TextChanged(object sender, EventArgs e)
        {
            txtheartbeats.Text = "enb";
        }
        private void txtname_TextChanged(object sender, EventArgs e)
        {
            txtname.Text = "John Smith";
        }
        private void txtDob_TextChanged(object sender, EventArgs e)
        {
            txtDob.Text = "05/10/1990";
        }
        private void txtTargetdate_TextChanged(object sender, EventArgs e)
        {
            txtTargetdate.Text = "11/10/2020";
        }

    }
}

Store your DOB as a DateTime - you can then subtract it from your target DateTime to give a TimeSpan[^]. You can then use the various properties to give you the basic numbers you need.


Its simple mathematics; x = a + b
What are you having difficulties with?

Also, setting the text, such as txtheartbeats.Text = "enb"; is doing nothing. It cancels out anything that is entered in the textboxes. You might as week just use a label.


In which case (and in future, please modify your question rather than answering yourself) you need to handle the Button.Click event, rather than the textbox.TextChanged event. All you will do in your existing code is go round an round in a loop:
txtTargetdate_TextChanged event sets text of txtTargetdate -> causes txtTargetdate_TextChanged event, which sets the text of ....

Instead, set the textbox.Text values in a single myButton_Click event, and remove the TextChanged event handler from all text boxes.


这篇关于我如何在Windows应用程序上进行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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