Click to See Complete Forum and Search --> : Forms binding to objects


Efitap
November 8th, 2008, 02:25 AM
public partial class ComPortSelection : Form
{
public ComPortSelection( )
{
InitializeComponent( );

selectComPortBindingSource.Add( new Presentation.SelectComPort( ) );
}



private void btnOk_Click(object sender, EventArgs e)
{
( selectComPortBindingSource.Current as SelectComPort ).OkPressed( );
}

}


The code above illustrates my problem.
I have created a class named Presentation.SelectComPort (yes, the name is horrible) for the purpose of being able to unit test every aspect of the GUI without having bound any code to the GUI itself.

My issue is: how do I bind events to the same class? So far, I'm forced to implement the events that I want to catch on the GUI, what I want is to bind an event to an event handler such as you can see a vague hint of on the btnOk_Click function.

The solution above is the closest thing I've managed to get working. I can unit test OkPressed, and the event is handled using the syntax, but I find it ugly and counter-intuitive.

Hints are welcome!