3

ああ、これは私を夢中にさせています。

小数点が間違った場所にあるのはなぜですか。

テキストボックスに文字列567があり、小数点ボタンをクリックすると、テキストボックスが567に変更されると予想されます(または希望します)が、代わりに.567を取得します

別の数字を追加したときにのみ正しい場所に移動します。たとえば、数字が 4 の場合、上記を実行した直後に 567.4 になります。

編集:

私のコード全体は次のとおりです。

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;
using System.IO;

namespace Calculator
{
    public partial class frmCurrencyCalc : Form
    {
        public frmCurrencyCalc()
        {
            InitializeComponent();
        }

        private void cmdZero_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "0";
            }
            else
            {
                txtScreen.AppendText("0");
            }
        }
        private void cmd1_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "1";
            }
            else
            {
                txtScreen.AppendText("1");
            }
        }

        private void cmdTwo_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "2";
            }
            else
            {
                txtScreen.AppendText("2");
            }
        }

        private void cmdThree_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "3";
            }
            else
            {
                txtScreen.AppendText("3");
            }
        }

        private void cmdFour_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "4";
            }
            else
            {
                txtScreen.AppendText("4");
            }
        }

        private void cmdFive_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "5";
            }
            else
            {
                txtScreen.AppendText("5");
            }
        }

        private void cmdSix_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "6";
            }
            else
            {
                txtScreen.AppendText("6");
            }
        }

        private void cmdSeven_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "7";
            }
            else
            {
                txtScreen.AppendText("7");
            }
        }

        private void cmdEight_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "8";
            }
            else
            {
                txtScreen.AppendText("8");
            }
        }

        private void cmdNine_Click(object sender, EventArgs e)
        {
            if (txtScreen.Text == "0")
            {
                txtScreen.Text = "9";
            }
            else
            {
                txtScreen.AppendText("9");
            }
        }

       private void cmdDecimal_Click(object sender, EventArgs e)
      {
          txtScreen.AppendText(".");
          cmdDecimal.Enabled = false;
      }


        private void cmdCancel_Click(object sender, EventArgs e)
        {
            txtScreen.Text = "0";
            cmdDecimal.Enabled = true;
        }
    }
}
4

7 に答える 7

1

私のアドバイスは、Right に設定することですが、NoTextAlignのままにしておくことです。RightToLeft

編集:そうは言っても、この問題はこれらの設定とは無関係かもしれません。

Windows Vista の Visual Studio 2008 で 2009 年初頭に友人がこれと同様のバグを抱えていたことを覚えています。不思議なことに、Windows XP 上の同じバージョンの Visual Studio では同じ問題は発生しませんでした。

Visual Studio / .NET 3.5 をService Pack 1に更新していない場合は、更新して問題が解決するかどうかを確認することをお勧めします。

于 2010-02-22T21:35:18.330 に答える
1

あなたのRightToLeft問題に見えます。MSDN で説明されているように、

RightToLeft プロパティは、ヘブライ語やアラビア語など、言語が右から左に記述される国際的なアプリケーションに使用されます。このプロパティが RightToLeft..::.Yes に設定されている場合、テキストを含むコントロール要素は右から左に表示されます。

以前の回答の 1 つが示唆したように、これは false に設定する必要がありますがTextAlign、実際の電卓の外観を模倣するために Right に設定する必要があります。

于 2010-02-22T21:42:20.993 に答える
1

私のアドバイスは、ビジネス層を定義することです。あなたの場合 - double 変数。ボタンのクリック時に、最初に変数を更新します。次に、値をフォーマットします。

于 2010-02-22T21:43:06.283 に答える
0

興味のある方のみお知らせします。

なんとか修正できました。私がしたことは、設計コードで右から左のものを削除してから、(GUI を使用して) 右に再配置することでした...前回と何も変わっていないので奇妙です...

しかたがない

ご協力ありがとうございました

高く評価された

バツ

于 2010-02-23T00:11:06.503 に答える
0

おそらく別の方法を試してください:

private void AddDecimal()
{
    txtScreen.SelectionLength = txtScreen.TextLength;
    txtScreen.SelectedText += ".";
}

(また、テキストボックス、テキストの配置、右揃えです...そうでない場合は、問題の原因となる可能性があります。)

于 2010-02-22T21:17:05.943 に答える
0

ここにいくつかのものがあると思います。

一見すると、次のように設定されています。

txt画面。右から左= true;

小数点だけを追加すると、記述した結果が得られます。次のようなものを使用してみてください:

txtScreen.AppendText(".00");

これにより、説明している結果が得られます。

ワームの缶を開けている可能性があります。テキストボックスのフォーマットを開始すると、値の保持からプレゼンテーションに変更されます。例えば:

decimal value = 567;
txtScreen.Text = value.ToString("0.00");

次に、567.00.1 などの値を避けるためにクレイジーな検証ルールを書き始める必要があります。

于 2010-02-22T21:27:38.217 に答える
0

あなたはこれを試すことができます、それは私のために働きます:

private void btndot_Click(object sender, EventArgs e)
{
    if (txtbox.Text == "0" && txtbox.Text != null)
    {
        txtbox.Text = ".";
    }
    else
    {
        txtbox.Text = txtbox.Text + ".";
    }
}
于 2022-02-16T09:22:13.163 に答える