PDA

View Full Version : [SOLVED] How to Create ActiveX Control in VB.Net? O! Please Help.


xolela
03-16-04, 01:21 AM
Can Some Body Correct My Code, I want to Create ActiveX Control and Embed it in a HTML Page. Currently, it doesn't diplay the Control on the form. In VB6 I used to come up with .OCX file but here, I just can't get it. Please help me out, I need this Very Urgently. Please tell me all the steps I need to do to accomplish my goal.


I also atthached the files

Here is the code for the ActiveX Control








Namespace ActiveXDotNet

Public Interface AxMyControl 'userControl

Property UserText() As String

End Interface 'AxMyControl


Public Class myControl

Inherits System.Windows.Forms.UserControl

Private mStr_UserText As String

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents txtUserText As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.txtUserText = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'txtUserText
'
Me.txtUserText.Location = New System.Drawing.Point(176, 8)
Me.txtUserText.Name = "txtUserText"
Me.txtUserText.Size = New System.Drawing.Size(176, 20)
Me.txtUserText.TabIndex = 0
Me.txtUserText.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(128, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "User Text"
'
'UserControl
'
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtUserText)
Me.Name = "UserControl"
Me.Size = New System.Drawing.Size(360, 40)
Me.ResumeLayout(False)

End Sub

#End Region

Public Property dd() As Integer
Get

End Get
Set(ByVal Value As Integer)

End Set
End Property


Public Property UserText() As [String]
Get
Return mStr_UserText
End Get
Set(ByVal Value As String)
mStr_UserText = Value
'Update the text box control value also.
txtUserText.Text = Value
End Set
End Property


End Class

End Namespace


Here is the code for the HTML Page

<html>
<body color=white>
<hr>

<font face=arial size=1>
<OBJECT id="myControl1" name="myControl1" classid="ActiveXDotNet.dll#ActiveXDotNet.myControl" width=288 height=72>
</OBJECT>
</font>

<form name="frm" id="frm">
<input type="text" name="txt" value="enter text here"><input type=button value="Click me" onClick="doScript();">
</form>
<hr>
</body>

<script language="javascript">
function doScript()
{
myControl1.UserText = frm.txt.value;
}
</script>
</html>


Thank You In Advance

Kaysetoaster
02-13-08, 02:25 AM
hi xolela,

I worked long hours to get this thing going and asked some colleagues. > Thanks to everyone btw :). It works on a IIS6 and IIS7 when you set the permissions to scripts only.

I attached the DLL file and the hole project, so that you can figure out if it was something in your coding. Its the very basics of a UserControl with a TextBox and a Label. In the Website is a form with a button and a inputfield. the text of the input field is transfered to the textbox in the usercontrol.

I guess thats the best way to understand the communication. :)


<html>
<head>
<script language="javascript">
function doScript()
{
alert(myControl1.UserText);
alert(myControl1.getUserText());
}
</script>
</head>

<body color=white>
<hr>

<font face=arial size=1>
<OBJECT id="myControl1" name="myControl1" classid="SoftwareCorner.dll#SoftwareCorner.myControl" width=288 height=72>
</OBJECT>
</font>

<form name="frm" id="frm">
<input type="text" name="txt" ><input type=button value="Click me" onClick="doScript();">
</form>

<div id="bla">
</div>

<hr>
</body>

</html>


Best Regards and Let me know if i could help you ;)
Steffen

Kaysetoaster
02-13-08, 02:30 AM
:) the important thing was the assembly file. in the Visual Studio its created with every class libary you create. (AssemblyInfo.vb). before you create a new usercontrol you have to do some changes in the assemblyInfo.vb: (thats what worked for me :))


how vb.net generates it (wrong):

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("TestProject")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Entenhausen")>
<Assembly: AssemblyProduct("TestProject")>
<Assembly: AssemblyCopyright("Copyright © Entenhausen 2008")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(True)>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("53b4e105-4b77-4267-a14e-af3375ee7f61")>

' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>


How it has to be done:


Imports System
Imports System.Reflection
Imports System.Runtime.CompilerServices

' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("TestProject")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Entenhausen")>
<Assembly: AssemblyProduct("TestProject")>
<Assembly: AssemblyCopyright("Copyright © Entenhausen 2008")>
<Assembly: AssemblyTrademark("")>



' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

<Assembly: AssemblyDelaySign(False)>
<Assembly: AssemblyKeyFile("")>
<Assembly: AssemblyKeyName("")>


Hope I could help you :) best Regards,
Steffen