Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > C#.net user control in VB6
 

C#.net user control in VB6

I have created a simple usercontrol in c# . It consist of three textboxes.

I have written a method in usercontrol to set the values in these textboxes

public partial class Win : UserControl

{

public Win()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

textBox3.Text = textBox1.Text + textBox2.Text;

}

public void CalVal()

{

textBox1.Text = "My";

textBox2.Text = "Name";

textBox3.Text = "Neeraj";

}

}

It is successfully registered as COM component .

When i use it in VB6 i am not able to set the values in these textboxes

Dim objControlNew As Try.Win

Private Sub Command2_Click()

Dim str As String
Dim strnew As String

Set objControlNew = New Try.Win

Me.Controls.Add objControlNew, "dotnet"
Me.Controls("dotnet").Visible = True
objControlNew.CalVal
End Sub

I am just calling the method , values are set from usercontrol , but i am not able to see the values in the textboxes.

Please help if anyone know the solution

Neon  Friday, June 01, 2007 6:32 AM

The scenario you're trying is actually unsupported unless you use the Interop Toolkit 2.0 (http://msdn2.microsoft.com/en-us/vbasic/bb419144.aspx). The templates for that are only in VB, but someone posted a C# translation over at CodeProject: http://www.codeproject.com/useritems/VB6InteropToolkit2.asp.

If you're building your .NET component in VB it's as simple as using the ComClass attribute; if you're using C# there's some extra work involved. Check out http://blogs.msdn.com/vbteam/archive/2007/06/01/so-what-does-lt-comclass-gt-actually-do.aspxfor more info.

Hope that helps,

Jonathan

Jonathan Aneja - MSFT  Saturday, June 02, 2007 4:01 AM

The scenario you're trying is actually unsupported unless you use the Interop Toolkit 2.0 (http://msdn2.microsoft.com/en-us/vbasic/bb419144.aspx). The templates for that are only in VB, but someone posted a C# translation over at CodeProject: http://www.codeproject.com/useritems/VB6InteropToolkit2.asp.

If you're building your .NET component in VB it's as simple as using the ComClass attribute; if you're using C# there's some extra work involved. Check out http://blogs.msdn.com/vbteam/archive/2007/06/01/so-what-does-lt-comclass-gt-actually-do.aspxfor more info.

Hope that helps,

Jonathan

Jonathan Aneja - MSFT  Saturday, June 02, 2007 4:01 AM
hello neyon

Im naren.i need to crete a text box usercontrol in windows application using c#.net same time how i can drag the textbox in user area.can any one help to me.
Naren
Naren7  Saturday, October 31, 2009 9:35 AM
@Naren7:
Not sure if this is relevant, but here goes:

If you are using the control in C# (MyControl for example), you can instantiate the control directly in code:

MyControl txtControl = new MyControl();
txtControl.Parent = this;
txtControl.Size = new Size(20, 60);
txtControl.Location = new Point(5, 5);
txtControl.Text = "";

Take a look at exactly what InitializeComponent() does in your form's constructor. That's what instansiates all the controls that you drag onto the form designer.
Live Fast, Die Young... Code Fast, Die Richer!
RobstaHendricks  Tuesday, November 17, 2009 3:09 PM

You can use google to search for other answers

Custom Search

More Threads

• How to get the entire Error list in VB.NET?
• Problem removing mappings using NATUPnP
• What RPC_E_SERVERCALL_RETRYLATER exception is throwing and how to solve?
• Interop Toolkit with VFP9.0 and C#
• VB.Net DLL for use from Outlook 2007 VBA
• Can Dsofile.dll component be used to read/write folder properties
• Debug in VB6, step into
• Using Excel In Visual Studio 2005
• Problem using CreateObject("TestObject.test") in a Windows Service using COM Interop
• VB6 vs VB 2008 Pro (novice .NET developer)