How to pass data and commands between VB form and C# form in same solution

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
Hi all.

I have a VB project with a C# project in the same solution. It works so far in that I can call (Show) the C# form from the VB form. The C# form is created as a Class Library, and is a dll which has a Reference in the VB project.

I want to pass data in the form of a variable from the VB form to the C# form and back again. How do I do this?
The VB form name is (say) frmVBForm, Public Class is VBForm.
The C# form name is (say) frmCSForm, Namespace is CSNameSpace and the class is public class CSClass : System.Windows.Forms.Form.

I have a value in the VB mnumThisValue which I want to pass to a similar variable in the C# form. Also back from C# to VB. How do I do this?

Also I need to set the VB form's TextBox1.Focus from within the C# from, how do I do this?

Thanks in advance.

Jonathan
 
The fact that these forms are in different projects and even that those projects are written in different languages is irrelevant. Passing data between any two forms is the same as passing data between any two objects because forms are objects like any other.

Follow the Blog link in my signature below and and check out my posts on Data Among Multiple Forms. Be sure to read all three parts because it's the third part that is the most important.
 
Back
Top