The problem is that code developed in VB to identify when a textarea click event has been raised work as expected. But having a very difficult time getting the same functionality in C#.
The web page simply has a javascript to take the text from a input text element and places it in a text area element and raises the text area click event.
Here's the vb code:
Public Class Form2
Inherits System.Windows.Forms.Form
Public doc As mshtml.HTMLDocumentClass
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents div As mshtml.HTMLTextAreaElement
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form2))
Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser
Me.Panel1 = New System.Windows.Forms.Panel
Me.Button1 = New System.Windows.Forms.Button
CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'AxWebBrowser1
'
Me.AxWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill
Me.AxWebBrowser1.Enabled = True
Me.AxWebBrowser1.Location = New System.Drawing.Point(120, 0)
Me.AxWebBrowser1.OcxState = CType(resources.GetObject("AxWebBrowser1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxWebBrowser1.Size = New System.Drawing.Size(376, 266)
Me.AxWebBrowser1.TabIndex = 0
'
'Panel1
'
Me.Panel1.Controls.Add(Me.Button1)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Left
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(120, 266)
Me.Panel1.TabIndex = 1
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 16)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Open Page"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(496, 266)
Me.Controls.Add(Me.AxWebBrowser1)
Me.Controls.Add(Me.Panel1)
Me.Name = "Form2"
Me.Text = "Form2"
CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).EndInit()
Me.Panel1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub AxWebBrowser_DocumentComplete(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles AxWebBrowser1.DocumentComplete
doc = Me.AxWebBrowser1.Document
Try
div = CType(doc.getElementById("FDCReturnValues"), mshtml.HTMLTextAreaElement)
div.attachEvent("onclick", New Object)
Catch ex As Exception
Throw ex
End Try
Dim str As String = ""
str = "test"
AddHandler div.onclick, AddressOf DivChanged
End Sub
Private Function DivChanged() As Boolean
'ByVal e As mshtml.IHTMLEventObj
Dim str As String
str = div.innerText
MessageBox.Show(div.innerText, "Div Content", MessageBoxButtons.OK)
End Function
Private Sub AxWebBrowser1_BeforeNavigate2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event) Handles AxWebBrowser1.BeforeNavigate2
RemoveHandler div.onclick, AddressOf DivChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.AxWebBrowser1.Navigate2("http://localhost/HTMLPage1.htm")
End Sub
End Class
Any help is greatly appreciated.
jboss