博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[原]Winform自定义控件在网页上的应用
阅读量:7083 次
发布时间:2019-06-28

本文共 2552 字,大约阅读时间需要 8 分钟。

 

研究了一阵子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
    }
}

超级简单的一个例子,没什么好说的,要注意的是控件类前面的几个属性[ComVisible(true)][Guid("5649B9CC-07BA-432a-A392-532EE2AFD190")]是必须的。

 

二、Visual Studio 2005命令提示注册控件到全局缓存,注意用windowscmd.exe进行注册不行,不认识命令。

注册命令是:regasm /codebase fullpath,其中codebase是必须的,要不然即使注册成功也不会在IE上显示。如图:

三、将注册好的控件放在网页上

<
html
>
    
<
head
>
        
<
title
>
DotNetEventInScript
</
title
>
    
</
head
>
    
<
body
>
        
<
object 
id
= "eventSource"
classid
="clsid:5649B9CC-07BA-432a-A392-532EE2AFD190"
 width
=100% 
height
=100% 
align
=alClient
>
        
</
object
>
        
<
script 
type
="text/javascript"
>
            
function eventSource::DoStart(Restart)
            
{
                alert(
"DoStart");
            }
            
function eventSource::DoStop()
            
{
                alert(
"DoStop");
            }
            
function eventSource::DoPause()
            
{
                alert(
"DoPause");
            }
        
</
script
>
    
</
body
>
</
html
>

测试看看,效果不错吧!

转载于:https://www.cnblogs.com/salonliudong/archive/2008/03/06/1093426.html

你可能感兴趣的文章
计算机的换行符
查看>>
新型序列化类库MessagePack,比JSON更快、更小的格式
查看>>
caffe中各层的作用:
查看>>
Linux--多网卡的7种Bond模式
查看>>
ADO 连接数据库,取到VT_DATE型日期转换成 int型
查看>>
react webpack.config.js 入门学习
查看>>
Skyfree的毕业论文 《系统封装与部署的深入研究》
查看>>
【USACO 3.2】Magic Squares
查看>>
【ASM】ASMSNMP用户已存在
查看>>
【GoLang】golang 中可变参数的 定义、传递 示例
查看>>
properties 配置文件中值换行的问题
查看>>
Azure 部署 Asp.NET Core Web App
查看>>
Masonry和FDTemplateLayoutCell 结合使用示例Demo
查看>>
linux 切换用户之后变成-bash-x.x$的解决方法
查看>>
用备份控制文件做不完全恢复下的完全恢复(数据文件备份<旧>--新建表空间--控制文件备份<次新>--日志归档文件<新>)...
查看>>
python下RSA加密解密以及跨平台问题
查看>>
详解Java Spring各种依赖注入注解的区别
查看>>
android 区分wifi是5G还是2.4G(转)
查看>>
多个构造器参数使用构建器
查看>>
模板方法模式(Template Method)
查看>>