簡體   English   中英

C#字符計數條件

[英]C# Character count condition

我怎么能把條件放在這里。 就像我輸入一個4位數字符一樣,它會放入一個前綴“ F-”。

try
{
    Service1 ws = new Service1();
    if (e.KeyChar == (char)13 && button1.Enabled == true)
    {
        inputtxt = F.Text.ToString();
        showpic(inputtxt);
        if (ws.VerifyEID(inputtxt) == false)
        {
            MessageBox.Show("You have entered an incorrect Employee ID. Please try again!", "Attendance Monitoring System", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            F.Text = null;
        }



        else
        {
             panel1.Visible = false;
             SqlToText(inputtxt);
             ShowOffset(inputtxt);
             if (BtnTimeIn.Visible == true)
             {
                 BtnTimeIn.Focus();
             }
             else
             {
                 BtnTimeOut.Focus();
             }
         }

     }

請幫助我,謝謝。

您可以將其插入代碼中:

inputtxt = inputtxt.StartsWith("F-") ? inputtxt : "F-" + inputtxt;

但是我個人會在文本框中添加該前綴,以使用戶清楚地輸入內容並讓他們鍵入更少的字符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM