Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using C# controls in Visual Basic or vice versa 1

Status
Not open for further replies.

Gameboy9

Programmer
Jun 8, 2001
39
US
Any idea on how to do this?

Thanks for any reply in advance.
 
if you mean vb as in vb 6.0 then you can use these in C# but adding it as a reference...selecting reference in your solution right click and select the appropriate ocx or dll or right click on your toolbox and you can add a reference that way.
 
You'd have to write your C# control with a COM wrapper (CCW) in order for VB6 to make use of it.

Chip H.
 
Sorry for my miscommunication - I'm talking about making a user control in C# and making it work in VB .NET or vice versa.
 
Works as standard if you don't use overloaded operators.

Craig
 
Sorry, thought you were talking about VB6.

It should work fine as long as:
- Don't use operator overloading (VB.NET doesn't have it)
- Don't use case-sensitive names (in C#, firstName and FirstName are different, in VB.NET they'd be regarded as the same method)
- Don't expose any custom attributes, or expect your control's users to use custom attributes (VB.NET doesn't have them)

Chip H.
 
But usercontrols are project specific... and projects are language specific.

You could use a server control written in vb w/ a c# web project, but I don't think you can use a user control, since it's tied to the particular project.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
If you create a "Control Library" project in Visual Studio, you can use the C# controls in VB projects transparently.

This presumes that you have created a User Control. This can be done for both Windows Forms and for Web Pages.

Once you have a Control Library you can use it in a VB or C# project in several ways. But particularly you can add the User Control to the Tools menu and use it like any other .NET control (Right click Tools menu, Customize..., add the Control Library)

VB controls can be used in C# projects & vice versa.

web controls:

windows form controls:
---
dino
 
I realize it's just semantics, but a user control cannot be added to the toolbox, and is tied to a project (and therefore a language) for web projects. I can't speak to windows forms projects.

I think what you're referring to are custom server controls. Those can be added to the toolbox and created in any .NET language, and are created by making a new "Control Library" project.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Possibly semantics as you say. I think we are in violent agreement. In either case, you are correct that a user control in a "regular" project cannot be added to the tools menu.

For Windows forms, a UserControl object in a Control Library Project can be added to the tools menu. The Control Library project can also be added to another solution. ---
dino
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top