1

I have 2 projects in one solution.

The main is a VB.net project and the secondary is a C# project. I want to call a form from the C# project from the VB.net project at the click of a button but I am unsure how.

I have read it is possible if I create the C# .dll and reference it but I cannot find a guide for this. Would anybody give me a step by step on how one would accomplish this please?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Tried adding project reference of c# project to vb.net project? – Chetan Jul 09 '17 at 10:38
  • yeah i have done that but i dont know how to then call the C# form from vb – Andrew Walker Jul 09 '17 at 11:36
  • I'm voting to close this question as off-topic because Stack Overflow is not a tutorial service. – Visual Vincent Jul 09 '17 at 12:09
  • @VisualVincent chill bro were not all coding masters im new to this and sometimes we all need a little help i looked before posting this but could not find a description i could understand fully. Just cause you might find everything coding wise easy doesn't mean we all do theirs no need for your attitude this site is meant to educate people by asking questions that's exactly what i did. Take it eazy enjoy your weekend – Andrew Walker Jul 09 '17 at 19:26
  • I'm not having an attitude, and I am quite calm (FYI the part of the message that says `I'm voting to close this as off-topic because...` is pre-entered when specifying a custom reason and not many people change it when they vote). But the fact remains: Stack Overflow is a site for enthusiastic and professional programmers helping, or needing help with, **specific** problems and questions. What you have here is not _**that**_ specific and can be classed as too broad since there are too many ways of doing what you ask. – Visual Vincent Jul 10 '17 at 00:39
  • `i looked before posting this but could not find a description i could understand fully` - Posting what you have found would've narrowed it down and it is recommended that you do so as stated in [How to ask](https://stackoverflow.com/help/how-to-ask): _"Even if you don't find a useful answer elsewhere on the site, including links to related questions that haven't helped can help others in understanding how your question is different from the rest."_ – Visual Vincent Jul 10 '17 at 00:54
  • _(Sorry for the spam, limited comment space)_ I'm not trying to be hostile against you or your question... I'm merely trying to follow this site's guidelines, and I find this question being in a bit of a gray zone. – Visual Vincent Jul 10 '17 at 00:55
  • 1
    @VisualVincent thanks for that explanation, sorry it just came across to me as a bit hostile, maby just read it wrong. I understand your point and will take care to adhere to what you have said in future. Thanks. – Andrew Walker Jul 10 '17 at 09:08
  • Well yes, perhaps the close reason does sound a bit hostile, but it's actually a quite common one and I've seen many others voting to close questions for the exact same reason. Though I understand your point and I will learn from what you said. In future situations like this I shall try to explain more so that the OP better understands _why_ I voted to close his/hers question. Thank you! – Visual Vincent Jul 10 '17 at 10:14

1 Answers1

6

It's a fairly simple and easy thing to do, and also common. Saves duplicating code across projects if you have multiple projects which all have a function which does the same thing.

  1. Right Click the VB project and click Add -> Reference...
  2. Press the Projects node on the left.
  3. Now hover over the C# project and click the checkbox that appears.

You've now added the reference. Beware that you cannot then reference the Vb project from the C# as Visual Studio will not allow this because you're creating a circular reference.

To call a form to show up, you can do the following.

First, you'll need to make a reference somewhere of the new form. For example; (OtherProject being the name of the other project, and FormName being the name of the form in the project. Depending on what you're doing, you might want to do this when you start your VB app, or you might only need it once. It entirely depends on your setup.

Dim OtherProjectForm as New OtherProject.FormName 

When you've done that, just go ahead and do

OtherProjectForm.Show()

or of course, again, depending what you're doing,

OtherProjectForm.ShowDialog()

You'll also be able to access and public members of the form. By default, every control on the form's access mode is "Friend", which means just objects which are part of the same assembly can access them, but if you need to, you can make them public. Or you can just make methods to interact with them.

halfer
  • 19,824
  • 17
  • 99
  • 186
Captain Obvious
  • 608
  • 5
  • 14
  • Thank you so so much for this, i had read similar but it was not explained as well as this its working perfectly now. I really appreciate you taking your time to answer this in such great detail – Andrew Walker Jul 09 '17 at 19:23