By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,677 Members | 1,138 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,677 IT Pros & Developers. It's quick & easy.

C# ActiveX-like User Control in .HTA file

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

http://www.c-sharpcorner.com/Code/20...tiveXInNet.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

}
}
---------------------------------------------

Thanks,

JA
Dec 9 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
gilad wrote:
Hi, I am trying to make an ActiveX-like control in C# per the following
article:

http://www.c-sharpcorner.com/Code/20...tiveXInNet.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
Dec 9 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.