Answered by:
C#.net user control in VB6

Question
-
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 StringSet objControlNew = New Try.Win
Me.Controls.Add objControlNew, "dotnet"
Me.Controls("dotnet").Visible = True
objControlNew.CalVal
End SubI 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
Friday, June 1, 2007 6:32 AM
Answers
-
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.aspx for more info.
Hope that helps,
Jonathan
Saturday, June 2, 2007 4:01 AMModerator
All replies
-
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.aspx for more info.
Hope that helps,
Jonathan
Saturday, June 2, 2007 4:01 AMModerator -
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.
NarenSaturday, 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!Tuesday, November 17, 2009 3:09 PM -
this code for runtime creation of controls . but i need free dragging in form using c#
NarenTuesday, December 29, 2009 10:10 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!
It's very useful, it makes me learn a lot.Friday, December 24, 2010 1:52 AM