Zitat |
Original von Daniel_g
Hallo Daniel_g!
Öffentliche Events, bei denen sich eine andere Form einklinken kann, können dazu benutzt werden. Die Events transpoertieren die benötigten Daten einfach mit, wenn sie gefeuert werden.
der Marcel |
hi, der Marcel!
Wenn du mir sagen könntest was mache ich verkehrt...
using System;
using System.Windows.Forms;
using System.Drawing;
public class MyForm : Form
{
private Button btAction = new Button();
private String [] text = {"1111111111111",
"2222222222222",
"3333333333333",
"4444444444444",
"5555555555555"};
public int index = 0;
public delegate void OnSetText(string str);
public event OnSetText doSetText;
public MyForm()
{
this.Text = "My simple Form in UltraEdit";
this.btAction.Location = new Point(0, 0);
this.btAction.Text = "Action";
this.btAction.Click += new EventHandler(this.Action);
this.Controls.Add(this.btAction);
}
private void Action(object source, EventArgs e)
{
if(this.index > 4) this.index = 0;
if (doSetText != null)
doSetText(this.text[index]);
index ++;
}
}
public class MyForm2 : Form
{
private TextBox txtText = new TextBox();
public MyForm2()
{
this.Text = "My simple Form in UltraEdit";
this.txtText.Location = new Point(0, 0);
this.txtText.Size = new Size(200, 25);
this.Controls.Add(this.txtText);
}
public void setUserName(string str)
{
this.txtText.Text = str;
}
}
class MainApp
{
public static void Main()
{
MyForm2 f2 = new MyForm2();
MyForm f = new MyForm();
f.doSetText += new f.OnSetText(f2.setUserName); //<---Fehler!
Application.Run(f);
}
}
Fehler:
2FormsMitEvents.cs(68,22): error CS0246: The type or namespace name 'f' could not be found (are you missing a using directive or an assembly reference?)