我试图在textbox1中划分自定义输入值,结果应该显示在textbox2中 [英] I have trying to divide the custom input value in textbox1 and result should be displayed in textbox2

查看:80
本文介绍了我试图在textbox1中划分自定义输入值,结果应该显示在textbox2中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在textbox1中输入数量,它应该用百分之几除,并自动将结果显示在textbox2中,即,任何人都可以帮助我在c#.net windows窗体应用程序中使用此代码。



我尝试了什么:



我试图输入值,但不接受该值。

if i input amount in textbox1 it should be divided with some percent and automatically the result should be displayed in textbox2 i.e., can anyone help me with this code in c#.net windows forms application.

What I have tried:

I have tried to input values but its not accepting the value.

推荐答案

首先尝试将值解析为数字:

double value;

Try to parse the value to a numeric first:
double value;
if (!double.TryParse(tbUserInput.Text, out value))
    {
    // Report problem to user
    ...
    return;
    }
tbOutput.Text = (value / (100 / percent)).ToString();


使用 TextChanged 活动



use TextChanged event

private void txtInput_TextChanged(object sender, EventArgs e)
        { 
             int value;
             int percent = 50;
             if (int.TryParse(txtInput.Text.Trim(), out value))
                 txtOutput.Text = ((value * percent) / 100).ToString();
             else
                 txtOutput.Text = "Not a valid Number";

        }


这篇关于我试图在textbox1中划分自定义输入值,结果应该显示在textbox2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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