使用C#的天花板功能有人吗? [英] Ceiling function using C# Anyone?

查看:83
本文介绍了使用C#的天花板功能有人吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是代码.
我在计算中需要使用上限功能,以便显示的文本不会超出文本框中的可用空间.
我已经在VB.Net中做到了这一点.我不知道如何在C#中执行相同的操作.我不是程序员;如果您乐于助人,这对我来说是一种爱好.
再次感谢.
卢卡恩

Ok guys this is the code.
I need the ceiling function in calculations so that the text displayed does not exceed the space available in the textbox.
I have done this in VB.Net. I have no clue as to how to perform the same in C#. I’m NOT a programmer; this is a hobby for me if you be so kind as to lend a helping hand.
Thanks again.
Lukann

private void GoButt_Click(object sender, RoutedEventArgs e)
{
    try
    {
        double VL = Convert.ToDouble(LO.Text);
        double VA = Convert.ToDouble(AO.Text);
        double VTS = Convert.ToDouble(VL * VA);
        //
        TSF.Text = VTS.ToString();
        TMS.Text = (VL * 12 / 16).ToString();
        TMT.Text = (VL * 2 / 10).ToString();
        TMSc.Text = (VL * 12 / 16 * 4).ToString();
        int idxGSL = GSL.SelectedIndex;
        int idxCSL = CSL.SelectedIndex;
        double tmp = (((idxCSL + 1) * VTS) / (32 + 4 * idxGSL));
        TGB.Text = String.Format("{0}",tmp);
        TGBS.Text = (VTS * 1.5 / 258).ToString();
    }
    catch(Exception)
    {
        //Do something meaningful here
    }
}

推荐答案

TGB.Text = (Math.Ceiling(VTS / 32 * (CSL.SelectedIndex +1))).ToString();


我了解编程是您的爱好,但这并不意味着您不应该提高您的技能.首先,我强烈建议使用更好的命名规则(控件的前缀,有意义的变量名等).

I understand that programming is your hobby, but it does not mean that you shouldn''t improve your skills. To start with I strongly suggest using better naming rules (prefixes for controls, meaningful variable names etc.).

private void GoButt_Click(object sender, RoutedEventArgs e)
        {
            double VL = 0;
            double VA = 0;
            int idxGSL = GSL.SelectedIndex;
            int idxCSL = CSL.SelectedIndex;
            if (!Double.TryParse(LO.Text, out VL))
            {
                // Optionally display a parsing error (e.g. using MessageBox.Show)
                return;
            }
            if (!Double.TryParse(AO.Text, out VA))
            {
                // Optionally display a parsing error (e.g. using MessageBox.Show)
                return;
            }
            if (idxGSL == -1 || idxCSL == -1)
            {
                return;
            }
            double VTS = VL * VA;
            double tmp = (((idxCSL + 1) * VTS) / (32 + 4 * idxGSL));
            TSF.Text = VTS.ToString();
            TMS.Text = (VL * 12 / 16).ToString();
            TMT.Text = (VL * 2 / 10).ToString();
            TMSc.Text = (VL * 12 / 16 * 4).ToString();
            TGBS.Text = (VTS * 1.5 / 258).ToString();

            // Is this what you want to achieve?
            TGB.Text = Math.Ceiling(tmp).ToString();
        }


这篇关于使用C#的天花板功能有人吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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