1
Follows code:
Form2:
public void ChangeLabel(string s)
{
labelX1.Text = s;
}
And in Form1:
private void button_MostrarSegundaTela_Click(object sender, EventArgs e)
{
if (Screen.AllScreens.Length > 1)
{
//Estendido
SegundaTela formulario = new SegundaTela();
Screen[] telas = Screen.AllScreens;
Rectangle bounds = telas[1].Bounds; // pode ser outro índice.
formulario.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
formulario.StartPosition = FormStartPosition.Manual;
formulario.Show();
}
else
{
//Duplicado, ou apenas 1 tela
MessageBox.Show("Estender");
}
}
private void label3_TextChanged(object sender, EventArgs e)
{
var result = label3.Text;
SegundaTela frm2 = new SegundaTela();
frm2.ChangeLabel(result);
}
The idea is, when to change label
from Form1, also change label
form2.
It doesn’t work. Apparently nothing.
Some solution ?
Have you checked if the Modifiers property is the same as public? In private mode you won’t let it change outside the class.
– Agnaldo
Yes, I already checked the property and is as Modifiers:
Public
.– Matheus Miranda
You are instantiating a form and changing the value of the label, ok so far. But where is the part that form is shown????
– Jéf Bueno
@LINQ edited post. Got better.
– Matheus Miranda
@Matheusmiranda realizes that it doesn’t make sense. You instantiate and display a form in the first if, in the quoted method a new instance of the form is created that is not even shown
– Jéf Bueno
Yes, I did it to make the screen black. When
label
for new, show...– Matheus Miranda
Regardless of the reason, it makes no sense to create a new instance. Move the variable to a more comprehensive scope.
– Jéf Bueno
True, it makes sense.
– Matheus Miranda
I don’t have 2 monitors but it worked right when I did the changing test
Screen.AllScreens.Length > 0
andRectangle bounds = telas[0].Bounds
– Fernando