[C#& ActiveX]将ActiveX事件附加到JavaScript并与Windows Control进行交互 [英] [C# & ActiveX] Attaching an ActiveX event to JavaScript and interact with Windows Control

查看:129
本文介绍了[C#& ActiveX]将ActiveX事件附加到JavaScript并与Windows Control进行交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我真的需要您的帮助来了解如何在Windows Control和JavaScript之间进行交互....

I really need your help to understand how I can interact between the Windows Control and the JavaScript....

我遵循了Karsten J.关于Gadget& ActiveX(

I followed the tutorial of Karsten J. about Gadget & ActiveX (http://blogs.msdn.com/karstenj/archive/2006/10/09/activex-wpf-gadget.aspx), but I can't make it work with ActiveX...

我的小工具非常基础....这是一个带有按钮的简单WPF控件...当我单击该按钮时,我希望它打开一个FlyOut页面.

My Gadget is very very basic.... it's a simple WPF control with a button... and when I click on the button I want that it opens a FlyOut page.

< 按钮 x:名称 = " button1 " 单击 = " btnOkClick " > 确定 </ 按钮 >

<Button x:Name="button1" Click="btnOkClick" >Ok</Button>

命名空间 WPFActiveX
{

namespace WPFActiveX
{

公共 部分 class UserControl1 :System.Windows.Controls. UserControl
{

public partial class UserControl1 : System.Windows.Controls.UserControl
{

public 按钮 myButton;

public Button myButton;

公共 UserControl1()
{

public UserControl1()
{

InitializeComponent();
this .myButton = button1;

InitializeComponent();
this.myButton = button1;

}

}

公共 无效 btnOkClick( 对象 发件人, EventArgs e)
{

public void btnOkClick(object sender, EventArgs e)
{

button1.Content + = "1" ;

button1.Content += "1";

}

}

}

命名空间 WindowsControlLibrary1
{

namespace WindowsControlLibrary1
{

[ ProgId ( 谢谢.KarstenJ" ), GuidAttribute ( "9ED54F84-A89D-4fcd-A854-44251E925F09" ), ComVisible ( true )]
public 部分 class UserControl1 : UserControl
{

[ProgId("Thanks.KarstenJ"), GuidAttribute("9ED54F84-A89D-4fcd-A854-44251E925F09"), ComVisible(true)]
public partial class UserControl1 : UserControl
{

ElementHost eHost;
WPFActiveX.
UserControl1 uc1;
public 委托 void FlyOutHandler ();
公共 事件 FlyOutHandler FlyOut;

ElementHost eHost;
WPFActiveX.
UserControl1 uc1;
public delegate void FlyOutHandler();
public event FlyOutHandler FlyOut;

公共 UserControl1()
{

public UserControl1()
{

InitializeComponent();

InitializeComponent();

}

私有 无效 UserControl1_Load( 对象 发件人, EventArgs e)
{

private void UserControl1_Load(object sender, EventArgs e)
{

eHost = ElementHost ();
eHost.Dock =
DockStyle .Fill;
uc1 =
WPFActiveX. UserControl1 ();
uc1.InitializeComponent();
eHost.Child = uc1;
this . Controls.Add(eHost);
uc1.myButton.Click + =
新建 System.Windows. RoutedEventHandler (btnOkClick);

eHost = new ElementHost();
eHost.Dock =
DockStyle.Fill;
uc1 =
new WPFActiveX.UserControl1();
uc1.InitializeComponent();
eHost.Child = uc1;
this.Controls.Add(eHost);
uc1.myButton.Click +=
new System.Windows.RoutedEventHandler(btnOkClick);

}

公共 无效 btnOkClick( 对象 发件人, EventArgs e)
{

public void btnOkClick(object sender, EventArgs e)
{

System.Diagnostics. Debug .WriteLine( "FlyOut()" );
SecurityPermission ( SecurityPermissionFlag .UnmanagedCode).断言();
//FlyOut();
CodeAccessPermission .RevertAssert();

System.Diagnostics.Debug.WriteLine("FlyOut()");
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();
//FlyOut();
CodeAccessPermission.RevertAssert();

}

}

}

< html >
< >
< title > Contenu du Gadget </ 标题 >
< 样式 >
主体 {
宽度 : 130 ;
height : 130 ;
边距 : 0px ;}
</ 样式 >
</ head >
< 主体 > ;

<html>
<head>
<title>Contenu du Gadget</title>
<style>
body {
width:130;
height:130;
margin:0px;}
</style>
</head>
<
body>

< object id ="WPFActiveX"
    
classid ="clsid:9ED54F84-A89D-4fcd-A854-44251E925F09"
   
高度 ="130"
     
宽度 ="130"
   
样式 ="background-color:Transparent;">
</
对象 >

<object id="WPFActiveX"
     
classid="clsid:9ED54F84-A89D-4fcd-A854-44251E925F09"
      
height="130"
     
width="130"
     
style="background-color:Transparent;">
</
object>

< 脚本 类型 ="text/javascript">
函数 FlyOut()
{
     
var fs = ActiveXObject( "WPFActiveX.UserControl2" );
System.Gadget.Flyout.file =
"default2.html" ;
      ;  System.Gadget.Flyout.show =
true ;
}
</ 脚本 >

<script type="text/javascript">
function FlyOut()
{
      
var fs = new ActiveXObject("WPFActiveX.UserControl2");
       System.Gadget.Flyout.file =
"default2.html";
       System.Gadget.Flyout.show =
true;
}
</script>

</ body >
</
html >

</body>
</
html>

[ ProgId ( 谢谢.KarstenJ" ), GuidAttribute ( "7c4ee919-54a9-4b11-bb45-2e3a1ad9b991" ), ComVisible ( true )]
public 部分 class UserControl2 : UserControl
{

[ProgId("Thanks.KarstenJ"), GuidAttribute("7c4ee919-54a9-4b11-bb45-2e3a1ad9b991"), ComVisible(true)]
public partial class UserControl2 : UserControl
{

公共 UserControl2()
{

public UserControl2()
{

InitializeComponent();

InitializeComponent();

}

私有 无效 UserControl2_Load( 对象 发件人, EventArgs e)
{
}

private void UserControl2_Load(object sender, EventArgs e)
{
}

}

< html >
< >
< 标题 > FlyOut页面 </ 标题 >
< 样式 type ="text/css">
body <字体大小= 2> {
<字体颜色=#ff0000大小= 2>宽度 <字体大小= 2>: <字体颜色=#0000ff大小= 2> 320 ;
高度 : 240 ;
边距 : 0px ;
}
</ 样式 >
</ >
<
body >

<
object id ="WPFActiveX"
     
classid ="clsid:7c4ee919-54a9-4b11-bb45-2e3a1ad9b991"
   
高度 ="240"
      
宽度 ="320"
   
样式 ="background-color:Transparent;">
</
对象 >

<html>
<head>
<title>FlyOut Page</title>
<style type="text/css">
body {
width:320;
height:240;
margin:0px;
}
</style>
</head>
<
body>

<
object id="WPFActiveX"
      
classid="clsid:7c4ee919-54a9-4b11-bb45-2e3a1ad9b991"
      
height="240"
      
width="320"
      
style="background-color:Transparent;">
</
object>

</ body >
</
html >

推荐答案

您收到什么错误?另外,您是否将用户控件注册为ActiveX对象?
What error are you receiving?  Also, did you register the user control as an ActiveX object?


这篇关于[C#&amp; ActiveX]将ActiveX事件附加到JavaScript并与Windows Control进行交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆