Hi I’m creating test application that has a user control with a Button that will be reference in a Form.

Is it possible to bind interface
public interface ICRUD
{
void Test();
}
to the user Control button1 click event
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//CALL ICRUD.Test() execute when click on form1 and then show I am Clicked
}
}
so that
i just need to implement only the interface functions to my form1.
Form1:
using System.Windows.Forms;
namespace TEST
{
public partial class Form1 : Form , ICRUD
{
public Form1()
{
InitializeComponent();
}
public void Test()
{
MessageBox.Show("I am Clicked");
}
}
}
Thanks in Regards.
This doesn’t seems right to me. It’s probably not the
Formthat should be implementing this interface. What’s more, the interface doesn’t bring anything here.But if you really want to do that, you can access the
ParentFormproperty, cast it to your interface and then call the method:Also, the convention in .Net is to write abbreviations (at least the long ones) the same as other words, so you should name your interface
ICrud.