- visualframework_src.zip
- sample
- CNN
- cls.cls
- MSSCCPRJ.SCC
- PrjCnn.dll
- PrjCnn.exp
- PrjCnn.lib
- PrjCnn.vbp
- PrjCnn.vbw
- DemoDoc
- MfcViewLib
- ObjManager
- VbComLib
- VBDoc
- MSSCCPRJ.SCC
- prjVBDoc.vbp
- prjVBDoc.vbw
- UD.dob
- VCSharpComLib
- VisualFrameWork
|
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace VCSharpComLib
{
//Declare a new delegate
[ComVisible(false)]
public delegate void CSharpObjEventHandler();
//Events interface
[Guid("6FB2615E-9C46-4B29-9357-14BA74A0A15E")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ICSharpObjEvent
{
//declare a event source
void NewEvent();
}
/// <summary>
/// summary of CSharpObj
/// </summary>
[Guid("7B00FED4-BD02-42E9-92B4-C18912A9F6DE")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComSourceInterfaces(typeof(ICSharpObjEvent))]
public class CSharpObj : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
//declare a event
public event CSharpObjEventHandler NewEvent;
//declare a method
public void NewMethod()
{
//raise event
NewEvent();
}
//dynamic load .Net component
public void LoadDotNetControl(string sLibraryName, string sControlName, string sName)
{
System.Reflection.Assembly mAssembly;
Type mType;
object mDynObj;
System.Reflection.PropertyInfo mPropertyInfo;
//load program assembly
mAssembly = System.Reflection.Assembly.Load(sLibraryName);
//get component type
mType = mAssembly.GetType(sLibraryName + "." + sControlName, true, true);
//create component instance
mDynObj = System.Activator.CreateInstance(mType);
//set component "Dock" property
mPropertyInfo= mType.GetProperty("Dock");
mPropertyInfo.SetValue(mDynObj, System.Windows.Forms.DockStyle.Fill,null);
//set component "Name" property
mPropertyInfo= mType.GetProperty("Name");
mPropertyInfo.SetValue(mDynObj, sName ,null);
//show component in current container
Controls.AddRange(new System.Windows.Forms.Control[]{( System.Windows.Forms.Control)mDynObj});
}
public CSharpObj()
{
// 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.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Blue;
this.button1.Location = new System.Drawing.Point(32, 48);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 40);
this.button1.TabIndex = 0;
this.button1.Text = "CSharpCtrl";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// CSharpObj
//
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(255)), ((System.Byte)(128)));
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Name = "CSharpObj";
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
Form1 pForm = new Form1();
pForm.Show();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.