English 中文(简体)
我的html文件将模拟活动分派给我。
原标题:assigning onmouseover event to my htmldocument is not working

I m从事一个项目,在该项目中,我撰写了“钟星号”申请,希望从因特网探索者的一个连续的轨道上获得目前这个要素。

我可以接手IHtmlDocument2号文件。

 DHTMLEventHandler myHandler = new DHTMLEventHandler(htmlDocument);
 myHandler.Handler += new DHTMLEvent(this.BrowserEventHandler);
 htmlDocument.onmouseover = myHandler;

而且,由于我不想让国际能源学会吃其他活动(一个著名但已解决的问题),我应该像现在这样建立一个超文本的EventHandler阶层:

public delegate void DHTMLEvent(IHTMLEventObj obj);

[ComVisible(true)]
public class DHTMLEventHandler
{
    public DHTMLEvent Handler;

    private IHTMLDocument2 Document;

    public DHTMLEventHandler(IHTMLDocument2 doc)
    {
        Document = doc;
    }

    [DispId(0)]
    public void Call()
    {
        Handler(Document.parentWindow.@event);
    }
}

我的BrowserEvent 手法也一样:

public void BrowserEventHandler(IHTMLEventObj e)
    {
    }

仍然空洞(但我想在曲线下拿到该元素的innerHtml),但这种方法仍然空空洞,我可以:

A first chance exception of type System.InvalidCastException occurred in FindText.exe

Whenever I move the mouse.

< Questions:

  1. Why I m getting this exception?
  2. Is it possible to get e.srcElement.innerhtml in a variable and use in my c# application?

让我知道,有点含糊不清。 事先感谢任何帮助和想法。 页: 1

<>Update:

为了回答我的第二个问题,似乎有可能获得<代码>e.srcElement.inner Rainbow/code>。 活动Obj e,但我确实不知道为什么从未使用方法。 任何想法或背后?

<><><>>>>

奥基先生,我发现这个问题。 第一,我改变了我的项目的一些环境,以适应例外情况首先发生的情况(因为它是第一个例外情形),例如:

在视觉演播室: Menu >> Debug >>Specialions > CLR的例外情况和特例;>系统和检查InvalidCastException系统的投掷选择。

我发现,问题在于<代码>D/2006/2EventHandler。 班级:

Handler(Document.parentWindow.@event); 

It throws Invalid Cast Exception which I think is related to Threads according to my recent searches.

I guess I should set ApartmentState to ApartmentState.STA. But I don t know how. any ideas?

最佳回答

Ok,I found the solution! :)

I needed to change DHTMLEventHandler class like this:

public delegate void DHTMLEvent(IHTMLEventObj obj);

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class DHTMLEventHandler
{
    private Thread currentThread;
    public DHTMLEvent Handler;

    private IHTMLDocument2 Document;

    public DHTMLEventHandler(IHTMLDocument2 doc)
    {
        Document = doc;
    }

    [DispId(0)]
     [STAThread]
    public void Call()
    {
        currentThread = Thread.CurrentThread;
       Thread parentWin = new Thread(new ThreadStart(pWindowHandler));
        parentWin.SetApartmentState(ApartmentState.STA);
        parentWin.Start();
        currentThread.Suspend();
       // Handler(Document.parentWindow.@event);

    }
    public void pWindowHandler()
    {
        Handler(Document.parentWindow.@event);
        currentThread.Resume();
    }
}

但是,如果有人试图利用我的解决方案,我不知道它是否在其他局势中产生任何副作用。 至少对我处以罚款!

问题回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签