Obviously you have two Forms, let’s call the main form of Form1
and the secondary of Form2
In the Form1
main you will have a button with click event similar to the below
private void button_Click(object sender, EventArgs e){
//Aqui você vai pegar o valor do textBox
string valor = textBoxCor.Text;
//Aqui chamar o outro form passando o valor como parâmetro
var form = new Form2(valor);
form.ShowDialog();
}
For this to work, you will need to add another constructor (or change the existing constructor) in the second form.
public Form2(string cor){
InitializeComponent();
labelCor.Text = cor; //O label está recebendo o valor que foi recebido por parâmetro
}
Related: What good is a builder?
Welcome to Stack Overflow Tour and edit your question.
– Marco Souza
First, you don’t need to tag visual-studio because your problem doesn’t have none relation to your IDE. Second, you don’t need to put the language in the question title, put it as a tag - that’s what they’re for. Third, have you tried anything? Post the code you already have so we can help you better, if you have not tried anything explain your problem better and put some pseudo-code if you think it can help our understanding. Finally, does the answer below meet your needs? If not, I will give you a more detailed answer.
– Jéf Bueno
You can always improve your questions/answers by clicking [Edit].
– Jéf Bueno
By the way, he’s already done the tour @Marconciliosouza
– Jéf Bueno
@jbueno I’ve already edited the title. I don’t know what else to add to help you, I simply ask for an example of a way to pass a string one way to the other as the title question, and the answer below does not meet my needs, no.
– André
Well, there is missing information: the second form will already be open or will be opened when you press the button?
– Jéf Bueno
I didn’t really pay attention to that detail because I knew how to open a new shape by pressing the button, but I already edited the question, I hope it’s already better
– André
@jbueno, when he had posted he had not yet done.
– Marco Souza
It had been almost an hour that he had done :P But without stress, it was just to comment really
– Jéf Bueno
xD deiam - me a discount, I’m only 14 years old come on..
– André