Return parameters from another form via click

Asked

Viewed 83 times

-1

I’m playing a poker game in C#, but I’m not able to establish a communication between 2 Forms, so the formPrincipal receives values from formSecundario, using the player class that exists in formPrincipal only I am calling the formSecundario sending the main as parameter(I believe this way I can access the class)

Contextualizing: at the time the player is in his turn and wants to increase his bet I open a new form asking him to enter the amount he wants to increase and if he confirms that he wants to send even.

frmAumentar aumento = new frmAumentar(this);
aumento.ShowDialog();//Isso no formPrincipal

While in formSecundario I’m getting like this

    public frmAumentar(frmPokerGame principal)
    {
        InitializeComponent();       
    }

But I need that in the button1 click event it sends the parameters of a textbox that is in the form. But I do not know how to send to the player.Balance the amount he has increased.

1 answer

1

Part of frmPrincipal:

public partial class frmPrincipal : Form
    {
        public Jogador jogador { get; set; }

        public frmPrincipal()
        {
            InitializeComponent();

            jogador = new Jogador();
            jogador.NomeJogador = "Nome do Jogador";
            jogador.Valor = "50.00";
        }

        private void btnAlterarValor_Click(object sender, EventArgs e)
        {
            frmAumentar aumento = new frmAumentar(this);
            aumento.ShowDialog();

            txtValor.Text = jogador.Valor;
        }

        private void frmPrincipal_Load(object sender, EventArgs e)
        {
            txtNome.Text = jogador.NomeJogador;
            txtValor.Text = jogador.Valor;
        }
    }

Part of frmAumentar

public partial class frmAumentar : Form
    {

        private frmPrincipal _principal { get; set; }
        public frmAumentar(frmPrincipal principal)
        {
            InitializeComponent();

            _principal = principal;
        }

        private void btnAlterarValor_Click(object sender, EventArgs e)
        {
            _principal.jogador.Valor = txtvalor.Text;
        }
    }

Player class

public class Jogador
    {
        public string NomeJogador { get; set; }
        public string Valor { get; set; }
    }
  • Thank you Daniel Gama you helped me so much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.