Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

.NET User Control intergated in VB6

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Petrica Lupu - 08 Sep 2003 11:01 GMT
Hello,

I made a user control in VB.NET and I want to access it in VB.6.0.
I tested it ActiveX Control Test Container and it worked fine but when I
tried to access it in a VB6 form, the control doesn't appear.
Can anybody help me on this problem (if it's possible).

Petrica
Dmitry Topolnik - 09 Sep 2003 11:24 GMT
See example:

using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

// Add in these using clauses for this example

using System.Runtime.InteropServices;

using System.Text;

using System.Reflection;

using Microsoft.Win32;

namespace WinCtrlLib1

{

/// <summary>

/// Summary description for UserControl1.

/// </summary>

[Guid("CE41F576-F0C9-4509-B1B6-BD710DA329CA")]

[ProgId("WinCtrlLib1.UserCtrl1")]

[ClassInterface(ClassInterfaceType.AutoDual)]

public class UserCtrl1 : System.Windows.Forms.UserControl

{

private System.Windows.Forms.TextBox txtBox;

private System.Windows.Forms.Button btnOK;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public UserCtrl1()

{

// This call is required by the Windows.Forms Form Designer.

InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if( components != null )

components.Dispose();

}

base.Dispose( disposing );

}

#region Component Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.txtBox = new System.Windows.Forms.TextBox();

this.btnOK = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// txtBox

//

this.txtBox.Location = new System.Drawing.Point(24, 24);

this.txtBox.Name = "txtBox";

this.txtBox.Size = new System.Drawing.Size(104, 20);

this.txtBox.TabIndex = 0;

this.txtBox.Text = "";

//

// btnOK

//

this.btnOK.Location = new System.Drawing.Point(40, 64);

this.btnOK.Name = "btnOK";

this.btnOK.TabIndex = 1;

this.btnOK.Text = "OK";

this.btnOK.Click += new System.EventHandler(this.btnOK_Click);

//

// UserCtrl1

//

this.Controls.Add(this.btnOK);

this.Controls.Add(this.txtBox);

this.Name = "UserCtrl1";

this.Size = new System.Drawing.Size(150, 104);

this.ResumeLayout(false);

}

#endregion

[ComRegisterFunction]

static void ComRegister(Type t)

{

string keyName = @"CLSID\" + t.GUID.ToString("B");

using( RegistryKey key =

Registry.ClassesRoot.OpenSubKey(keyName, true) )

{

key.CreateSubKey("Control").Close();

using( RegistryKey subkey = key.CreateSubKey("MiscStatus") )

{

subkey.SetValue("", "131457");

}

using( RegistryKey subkey = key.CreateSubKey("TypeLib") )

{

Guid libid = Marshal.GetTypeLibGuidForAssembly(t.Assembly);

subkey.SetValue("", libid.ToString("B"));

}

using( RegistryKey subkey = key.CreateSubKey("Version") )

{

Version ver = t.Assembly.GetName().Version;

string version =

string.Format("{0}.{1}",

ver.Major,

ver.Minor);

if( version == "0.0" ) version = "1.0";

subkey.SetValue("", version);

}

}

}

[ComUnregisterFunction]

static void ComUnregister(Type t)

{

// Delete entire CLSID\{clsid} subtree

string keyName = @"CLSID\" + t.GUID.ToString("B");

Registry.ClassesRoot.DeleteSubKeyTree(keyName);

}

private void btnOK_Click(object sender, System.EventArgs e)

{

MessageBox.Show(this.txtBox.Text);

}

}

}

> Hello,
>
[quoted text clipped - 4 lines]
>
> Petrica

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.