i want a button that when it's pushed a new string is showen in the textboxes
what am i doing wrong
can somone inlight me why doesnt this code works ? ...
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public event Startdelegate StartEvent;
myButton button;
newTb[] tb;
public Form1()
{
InitializeComponent();
button = new myButton();
button.Parent = this;
button.Location = new Point(120, 0);
button.Text = "click on me!!!";
tb = new newTb[8];
for (int i = 0; i <= 80; i += 15)
{
tb[i / 15] = new newTb();
tb[i / 15].Parent = this;
tb[i / 15].Location = new Point(i + i, i + i);
// button.Subscribe(tb[i / 15]);
}
button.Click += new EventHandler(button_Click);
}
private void button_Click(object sender, EventArgs e)
{
button.s = "this is clicking";
//button.Notify();
}
}
public class myButton : Button, IObservable<newTb>
{
public string s;
private List<IObserver<newTb>> observers;
public myButton()
{
observers = new List<IObserver<newTb>>();
}
public IDisposable Subscribe(IObserver<newTb> observer)
{
if (!observers.Contains(observer))
{
observers.Add(observer);
}
return new Unsubscriber(observers, observer);
}
protected void Notify(newTb tb)
{
foreach (IObserver<newTb> observer in observers)
{
observer.OnNext(tb);
}
}
#region Unsubscriber
private class Unsubscriber : IDisposable
{
private List<IObserver<newTb>> observers;
private IObserver<newTb> observer;
public Unsubscriber(List<IObserver<newTb>> observers, IObserver<newTb> observer)
{
this.observers = observers;
this.observer = observer;
}
public void Dispose()
{
if (observer != null && observers.Contains(observer))
{
observers.Remove(observer);
}
}
}
#endregion
class newTb : TextBox, IObserver<string>
{
string s;
public void OnCompleted() { }
public void OnError(Exception error) { }
public void OnNext(string value)
{
this.Text = value;
}
}
}
}