Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 如何从同一文本框C获取输出和输入#_Winforms_C# 4.0 - Fatal编程技术网

Winforms 如何从同一文本框C获取输出和输入#

Winforms 如何从同一文本框C获取输出和输入#,winforms,c#-4.0,Winforms,C# 4.0,我有一个函数AuthenticateUser();内模1_荷载 private void Form1_Load(object sender, EventArgs e) { AuthenticateUser(); } 我的函数AuthenticateUser()只打印winform文本框中的第一行 “请输入您的帐号:”然后它将永远无法获得输入或显示其余的问题 下面是AuthenticateUser()函数: private void Authe

我有一个函数AuthenticateUser();内模1_荷载

     private void Form1_Load(object sender, EventArgs e)
    {
        AuthenticateUser();

    }
我的函数AuthenticateUser()只打印winform文本框中的第一行 “请输入您的帐号:”然后它将永远无法获得输入或显示其余的问题

下面是AuthenticateUser()函数:

    private void AuthenticateUser() // attempt to authenticate user against database
    {

        pantalla.Text = screen.DisplayMessage("\nPlease enter your account number:\n"); 

       int accountNumber = int.Parse(pantalla.Text);//enter the account number



        //pantalla.Text = accountNumber.ToString();

        pantalla.Text = screen.DisplayMessage("\nEnter your PIN: ");
        int pin = Convert.ToInt32(pantalla.Text);

        // set userAuthenticated to boolean value returned by database
        userAuthenticated = bankDatabase.AuthenticateUser(accountNumber, pin);

        // check whether authentication succeeded
        if (userAuthenticated)
        {
            currentAccountNumber = accountNumber; // save user's account #
            pantalla.Text = currentAccountNumber.ToString();
        }
        else
            pantalla.Text = screen.DisplayMessageLine("Invalid account number or PIN.Please try again.");                                           

    }
输出:

[1:


在这里,我输入了帐号,但它什么也不做!!只是卡在那里,它甚至不读取下一个输入。

如果使用UserControl,不是更好吗

public Class ATMDialer : UserControl
{
  TextBox txt = new TextBox();
  Button _b1 = new Button();
  Button _b2 = new Button();
  .
  .
  .

  _b1.Clicked += new EventHandler(OnButtonClicked);
  _b2.Clicked += new EventHandler(OnButtonClicked);
  .
  .
  .
  private void OnButtonClicked(object sender, EventArgs e)
  {
    Button b = (Button)sender;
    txt.Text = txt.Text + b.Text;
  }
}
}屏幕类别:

     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;

namespace ATM2
{

public class Screen
{
    public string DisplayMessage(string message)
    {
        string lineAbc;
        lineAbc = message;
        return lineAbc;
    }


    public string DisplayMessageLine(string message)
    {
        string lineAbc;
        lineAbc= message;
        return lineAbc;

    }


    public void DisplayDollarAmount(decimal amount)
    {
        Console.Write("{0:C}", amount);
    }

}


}

您正在一个函数中完成UI线程上的所有工作。您需要某种事件来完成此任务。可能是按钮单击事件。您可以详细说明一下吗?请尝试textBox1.AppendLine(“某物”);您是否共享pantalla和screen类。您的按钮事件在哪里?您的文本框(屏幕)的属性是什么?
     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;

namespace ATM2
{

public class Screen
{
    public string DisplayMessage(string message)
    {
        string lineAbc;
        lineAbc = message;
        return lineAbc;
    }


    public string DisplayMessageLine(string message)
    {
        string lineAbc;
        lineAbc= message;
        return lineAbc;

    }


    public void DisplayDollarAmount(decimal amount)
    {
        Console.Write("{0:C}", amount);
    }

}


}