マウスオーバーをしている時間の計測
投稿者 そそそ  (学生)
投稿日時
2011/6/30 21:27:52
すみません、自己解決しました。
まだ不完全ですがコードを載せておきます。
Imports System.Runtime.InteropServices.Marshal
Public Class Form1
Private watch As New Stopwatch()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("http://www.google.co.jp/")
Timer1.Interval = 20
Timer1.Enabled = True
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'WebBrowser1.Document.AttachEventHandler("onmouseup", AddressOf document_onmouseup)
WebBrowser1.Document.AttachEventHandler("onmouseover", AddressOf document_onmouseover)
WebBrowser1.Document.AttachEventHandler("onmouseout", AddressOf document_onmouseout)
End Sub
Sub document_onmouseover(ByVal sender As Object, ByVal e As EventArgs)
TextBox1.Text = WebBrowser1.Document.GetElementFromPoint(WebBrowser1.PointToClient(Control.MousePosition)).OuterText
TextBox2.Text = WebBrowser1.Document.GetElementFromPoint(WebBrowser1.PointToClient(Control.MousePosition)).OuterHtml
TextBox3.Text = Control.MousePosition.ToString
watch.Start()
End Sub
Sub document_onmouseout(ByVal sender As Object, ByVal e As EventArgs)
RichTextBox1.Text = WebBrowser1.Document.GetElementFromPoint(WebBrowser1.PointToClient(Control.MousePosition)).OuterHtml + watch.Elapsed.ToString + Chr(13) & Chr(10) + RichTextBox1.Text
watch.Stop()
watch.Reset()
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Label1.Text = watch.Elapsed.ToString()
End Sub
End Class
まだ不完全ですがコードを載せておきます。
Imports System.Runtime.InteropServices.Marshal
Public Class Form1
Private watch As New Stopwatch()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("http://www.google.co.jp/")
Timer1.Interval = 20
Timer1.Enabled = True
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'WebBrowser1.Document.AttachEventHandler("onmouseup", AddressOf document_onmouseup)
WebBrowser1.Document.AttachEventHandler("onmouseover", AddressOf document_onmouseover)
WebBrowser1.Document.AttachEventHandler("onmouseout", AddressOf document_onmouseout)
End Sub
Sub document_onmouseover(ByVal sender As Object, ByVal e As EventArgs)
TextBox1.Text = WebBrowser1.Document.GetElementFromPoint(WebBrowser1.PointToClient(Control.MousePosition)).OuterText
TextBox2.Text = WebBrowser1.Document.GetElementFromPoint(WebBrowser1.PointToClient(Control.MousePosition)).OuterHtml
TextBox3.Text = Control.MousePosition.ToString
watch.Start()
End Sub
Sub document_onmouseout(ByVal sender As Object, ByVal e As EventArgs)
RichTextBox1.Text = WebBrowser1.Document.GetElementFromPoint(WebBrowser1.PointToClient(Control.MousePosition)).OuterHtml + watch.Elapsed.ToString + Chr(13) & Chr(10) + RichTextBox1.Text
watch.Stop()
watch.Reset()
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Label1.Text = watch.Elapsed.ToString()
End Sub
End Class
ある要素にどのくらいの時間マウスが停滞していたかを測りたいのですがどうすればよいでしょうか?
現在のプログラムは以下のようになっています。
Imports System.Runtime.InteropServices.Marshal
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("http://www.google.co.jp/")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'WebBrowser1.Document.AttachEventHandler("onmouseup", AddressOf document_onmouseup)
WebBrowser1.Document.AttachEventHandler("onmouseover", AddressOf document_onmouseover)
End Sub
Sub ReleaseObject(ByVal o As Object)
If o IsNot Nothing AndAlso IsComObject(o) Then
ReleaseComObject(o)
End If
End Sub
Sub document_onmouseover(ByVal sender As Object, ByVal e As EventArgs)
TextBox1.Text = WebBrowser1.Document.GetElementFromPoint(WebBrowser1.PointToClient(Control.MousePosition)).OuterText
TextBox2.Text = WebBrowser1.Document.GetElementFromPoint(WebBrowser1.PointToClient(Control.MousePosition)).OuterHtml
End Sub
End Class