【IT168技术文档】
研究了一阵子C#版WorldWind,大家知道WorldWind是桌面程序,突然提了一个新需求,就是在IE里面运行WorldWind,对于java版的WorldWind来说可能比较容易,C#版的还真费神,我的做法是把WorldWindow以及自己的写的插件全部封装在一个winform自定义控件中,然后再把这个控件加载到webform上,效果非常好。
现在写一个简单的例子总结一下winform自定义控件在webform上使用的步骤。
一、制作winform自定义控件。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace EventSourceCtrl { public delegate void Start(Boolean Restart); public delegate void Stop(); public delegate void Pause(); [GuidAttribute("1A585C4D-3371-48dc-AF8A-AFFECC1B0967")] [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] public interface ButtonEvents { [DispId(0)] void DoStart(Boolean Restart); [DispId(1)] void DoStop(); [DispId(2)] void DoPause(); } public interface IDoNetEventInScript { void SetCaption(string Value); } [ComVisible(true)] [ClassInterface(ClassInterfaceType.None)] [ComSourceInterfaces(typeof(ButtonEvents))] [Guid("5649B9CC-07BA-432a-A392-532EE2AFD190")] public partial class sourceCtrl : UserControl, IDoNetEventInScript { public event Start DoStart; public event Stop DoStop; public event Pause DoPause; public sourceCtrl() { InitializeComponent(); } private void button1_Click_1(object sender, EventArgs e) { if (DoStart != null) { DoStart(true); } } private void button2_Click(object sender, EventArgs e) { if (DoPause != null) { DoPause(); } } private void button3_Click(object sender, EventArgs e) { if (DoStart != null) { DoStart(false); } } private void button4_Click(object sender, EventArgs e) { if (DoStop != null) { DoStop(); } } IDoNetEventInScript 成员#region IDoNetEventInScript 成员 public void SetCaption(string Value) { label1.Text = Value; } #endregion } }