Question

My first time asking a question here so apologies upfront if I'm not doing this right. I could not find anything with the search.

I inherited a VB.NET legacy Windows Application project. Any and all new additions as far as possible I would like to code in C#, including new Windows Forms. So, I have a new Windows form in a C# assembly (not sure if this is the best way) being referenced by the VB.NET Windows application. On initialising the C# form from the referenced assembly I pass it all the necessary parameters from which I will build up my grid columns and records in the C# Windows Form. No problems here so far. On the cell-double click event of the C# grid, I would like to show an existing VB.NET Winform from the application referencing the C# assembly. My question is: How do I get a handle on the VB.NET Windows Form to show it, or do anything else with it for that matter? Circular reference is obviously not allowed so how can I achieve this if at all possible, C# or otherwise?

Was it helpful?

Solution

You should be able to add an event handler to the object.

http://msdn.microsoft.com/en-us/library/6yyk8z93%28v=vs.90%29.aspx

OTHER TIPS

One way would be to pass a generic form creation handler to your C# Form, given that it is instantiated from your VB.NET code. This way the form wouldn't have to know what exact type of form it must create and show; all it would know is that it's a Form, which is good enough if all you have to do is showing it.

You may also consider exposing your C# Form cell double click event as a public event that can be handled by your VB.NET code.

If it makes sense in your design, a third option would be to use a third assembly that acts as a bridge. This assembly could be referred by both your VB.NET and C# assemblies and hold interface types implemented / used in these.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top