C# ActiveX-like User Control in .HTA file

G

gilad

Hi, I am trying to make an ActiveX-like control in C# per the following
article:

http://www.c-sharpcorner.com/Code/2003/March/ActiveXInNet.asp

The control I make compiles, but when I added it to my HTML Application
(.HTA) file, it won't display. I found another article that said this
would run only as HTML from a webserver. I tried this and it works. I
want to run this from a .HTA file, with no web server involved. Is it
possible? Do I perhaps have something wrong with the code?

Here is what the .HTA file looks like:

---------------------------------------------
<html>
<body>

<OBJECT id="OutLogCtl1"
classid="AXOutLog.dll#AXOutLog.OutLogCtl" width="352" height="80">
</OBJECT>
</body>

</html>
---------------------------------------------

And the C# library code:

---------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace AXOutLog
{

public interface AXOutLogCtl
{
string addString { set; get; }
}

/// <summary>
/// Summary description for OutLogCtl.
/// </summary>

public class OutLogCtl : System.Windows.Forms.UserControl, AXOutLogCtl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.TextBox textBox1;

private string lastAdd;

public string addString
{

get { return lastAdd; }

set
{
textBox1.Text = textBox1.Text + value;
lastAdd = value;
}
}

public OutLogCtl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitForm 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.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 8);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(336, 64);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// OutLogCtl
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1});
this.Name = "OutLogCtl";
this.Size = new System.Drawing.Size(352, 80);
this.ResumeLayout(false);

}
#endregion

}
}
 
G

gilad

gilad said:
Hi, I am trying to make an ActiveX-like control in C# per the following
article:

http://www.c-sharpcorner.com/Code/2003/March/ActiveXInNet.asp

The control I make compiles, but when I added it to my HTML Application
(.HTA) file, it won't display. I found another article that said this
would run only as HTML from a webserver. I tried this and it works. I
want to run this from a .HTA file, with no web server involved. Is it
possible? Do I perhaps have something wrong with the code?

Not to answer my own question, but this works if you do a "regasm
/codebase <dllname>", then look up the CLSID in the registry and access
it in the "standard" ActiveX way, i.e. with a GUID. My .HTA file looks like

<html>
<body>

<OBJECT id="OutLogCtl1"
classid="CLSID:B1943A0E-C4EB-3308-A9EE-3AF1789B5572" width="352"
height="80">
</OBJECT>
</body>

</html>

and the control loads. Is this the only way to make this work on .HTA files?

Thanks,

JA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top