如果第一个文本块的文本长度有限,如何将文本从一个文本块继续到另一个文本框

本文关键字:文本 一个 另一个 继续 第一个 如果 | 更新日期: 2023-09-27 17:57:33

我正在创建一张银行支票,因此我有6个文本块,第一个是支票上的日期和名称,第三个、第四个、第五个是大写金额,第六个是小写金额,因此我所在组织的最终用户将提供日期,数字中的名称和金额以及数字中的金额将被重新编辑并转换为文字中的金额,直到这里,这很好,但我的要求是在第三个溢出中,我想继续第四个文本块中的文本。

public ICICICHEQUE()
    {
        InitializeComponent();
        if (!this.IsVisible)
        {
            this.Show();
        }
        this.WindowState = WindowState.Normal;
        this.WindowState = WindowState.Minimized;
        this.Activate();
        this.Topmost = true;
        this.Focus();
        this.ShowInTaskbar = true;
        if (txtblckAmountInFigures.Text != null)
        {
            ConvertTxtBlockInDecimal();
        }

    }
    private void ConvertTxtBlockInDecimal()
    {
        txtblckAmountInWords.Text = UtilityMethods.ConvertToWords(Convert.ToDecimal(txtblckAmountInFigures.Text), "isCheque") + "only/-"+"'r'n";
    }

如果第一个文本块的文本长度有限,如何将文本从一个文本块继续到另一个文本框

您需要拆分代码并使用这两种方法

public static string DecimalToText(string decimalPart)
{
   string[] digits = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
   string result = "";
   foreach(char c in decimalPart)
   {
       int i = (int)c - 48;
       if (i < 0 || i > 9) return ""; // invalid number, don't return anything
       result += " " + digits[i];
   }
   return result;
}
public static string NumberToText(int number, bool useAnd, bool useArab)
{
    if (number == 0) return "Zero";
    string and = useAnd ? "and " : ""; // deals with using 'and' separator
    if (number == -2147483648) return "Minus Two Hundred " + and + "Fourteen Crore Seventy Four Lakh Eighty Three Thousand Six Hundred " + and +"Forty Eight";
    int[] num = new int[4];
    int first = 0;
    int u, h, t;
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    if (number < 0)
    {
        sb.Append("Minus ");
        number = -number;
    }
    string[] words0 = {"" ,"One ", "Two ", "Three ", "Four ", "Five " ,"Six ", "Seven ", "Eight ", "Nine "};
    string[] words1 = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "};
    string[] words2 = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ","Eighty ", "Ninety "};
    string[] words3 = { "Thousand ", "Lakh ", "Crore " };
    num[0] = number % 1000; // units
    num[1] = number / 1000;
    num[2] = number / 100000;
    num[1] = num[1] - 100 * num[2]; // thousands
    num[3] = number / 10000000; // crores
    num[2] = num[2] - 100 * num[3]; // lakhs
    for (int i = 3; i > 0; i--)
    {
        if (num[i] != 0)
        {
            first = i;
            break;
        }
    }
    for (int i = first; i >= 0; i--)
    {
        if (num[i] == 0) continue;
        u = num[i] % 10; // ones 
        t = num[i] / 10;
        h = num[i] / 100; // hundreds
        t = t - 10 * h; // tens
        if (h > 0) sb.Append(words0[h] + "Hundred ");
        if (u > 0 || t > 0)
        {
            if (h > 0 || i < first) sb.Append(and);
            if (t == 0)
                sb.Append(words0[u]);
            else if (t == 1)
                sb.Append(words1[u]);
            else
                sb.Append(words2[t - 2] + words0[u]);
        }
        if (i != 0) sb.Append(words3[i - 1]);
    }
    string temp = sb.ToString().TrimEnd();
    if (useArab && Math.Abs(number) >= 1000000000)
    {
        int index = temp.IndexOf("Hundred Crore");
        if (index > -1) return temp.Substring(0, index) + "Arab" + temp.Substring(index + 13);
        index = temp.IndexOf("Hundred");
        return temp.Substring(0, index) + "Arab" + temp.Substring(index + 7);
    } 
    return temp;
}

}

使用子字符串拆分文本并显示在2个文本框中。

var requiredText = UtilityMethods.ConvertToWords(Convert.ToDecimal(txtblckAmountInFigures.Text), "isCheque") + "only/-"+"'r'n";
if(requiredText.Count > 255)
{
    textbox1.Text = requiredText.subString(0,255);
    textbox2.Text = requiredText.subString(255,requiredText.Count-1);
}
else
{
    textbox1.Text = requiredText;
}