Stworzyłem 2 formatki.
Pierwsza posiada button, który generuje formatke druga.
Formatka druga posiada button i textbox. Po nacisnieciu buttona chcę wywołać metode nalezaca do formy 1.
Zrobiłem to w taki sposób, lecz messagebpx wyswietlany jest bez przerwy po zamknieciu poprzedniego msgboxa.
Czy da sie uprosic kod? Jak wyeliminowac ten błąd?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 forma = new Form2();
forma.TextSend += new WindowHandler(Show);
forma.ShowDialog();
}
private void Show(object o, WindowEventArgs wea)
{
MessageBox.Show("message!"+wea.Text);
}
}
public delegate void WindowHandler(object sender, WindowEventArgs WindowInfo);
public class WindowEventArgs : EventArgs
{
public WindowEventArgs(string text)
{
this.Text = text;
}
public readonly string Text;
}
public partial class Form2 : Form
{
public event WindowHandler TextSend;
public Form2()
{
InitializeComponent();
}
protected void onTextSend(object sender, WindowEventArgs windowInfo)
{
if (TextSend != null)
{
TextSend(this, windowInfo);
}
}
private void Form2_Load(object sender, EventArgs e)
{
TextSend += new WindowHandler(onTextSend);
}
private void button1_Click(object sender, EventArgs e)
{
WindowEventArgs wea = new WindowEventArgs(textBox1.Text);
onTextSend(this, wea);
}
}