我们打开了 2 个窗口,就像聊天一样
这是文本框和按钮的样子:
private void textBox_chat_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void button_enviar_Click(object sender, RoutedEventArgs e)
{
string chatMessage = textBox_chat.Text;
}
我想知道如何通过按下按钮“button_enviar”来发送插入文本框中的信息。并打印到另一个窗口。我一直在寻找类似的东西Application.Current.Windows
......但仍然没有找到制作它的方法。
我的代码实际上是这样的:
主窗口
namespace WpfApplication1
{
/// <summary>
/// Lógica de interacción para MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
// automatic code generated by the button
private void button_entrar_Click(object sender, RoutedEventArgs e)
{
// we catch the taxt input in the texBox
string userLoginName = textBox_pantalla_inicial.Text;
// We call the chat window
Window window1 = new Window1();
// we put the user name as the title of the chat window
window1.Title = userLoginName;
// show the chat window
window1.Show();
}
}
}
聊天窗口
namespace WpfApplication1
{
/// <summary>
/// Lógica de interacción para Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
// inicialize chatWindow
InitializeComponent();
}
private void textBox_chat_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void button_enviar_Click(object sender, RoutedEventArgs e)
{
string chatMessage = textBox_chat.Text;
}
private void button_erase_Click(object sender, RoutedEventArgs e)
{
}
}
}