C# webBrowser 返回鼠标点击的位置如何写?

cannycsy 2009-01-19 12:06:44
C# webBrowser 返回鼠标点击的位置如何写?

webBrowser1.Document.Body.ScrollLeft
webBrowser1.Document.Body.ScrollTop

上面这两个只返回就是顶点0,如何加上鼠标点下的位置,对webBrowser1属性不了解.


...全文
653 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
cklvxd 2010-09-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 xtmyd 的回复:]
private void webBrowser1_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser1.Document.MouseDown += new HtmlElementEventHandler(Document_Mo……
[/Quote]

为什么鼠标点一下,会相应两下;
例, 在MOuseUp里,加 count++, count每次会加2,为什么
幻影 2009-02-02
  • 打赏
  • 举报
回复
private void webBrowser1_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser1.Document.MouseDown += new HtmlElementEventHandler(Document_MouseDown);
WebBrowser1.Document.MouseMove += new HtmlElementEventHandler(Document_MouseMove);
WebBrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);
}

private void Document_MouseDown(object sender, HtmlElementEventArgs e)
{
// Insert your code here.
}

private void Document_MouseMove(object sender, HtmlElementEventArgs e)
{
// Insert your code here.
}

private void Document_MouseUp(object sender, HtmlElementEventArgs e)
{
// Insert your code here.
}
tongget 2009-02-01
  • 打赏
  • 举报
回复
不能动态使用.
winner2050 2009-01-19
  • 打赏
  • 举报
回复
好像不行.

不过可以通过在窗体里面的鼠标事件得到,鼠标在窗体里面的位置.
qiqundelang 2009-01-19
  • 打赏
  • 举报
回复
路过
bizbuy 2009-01-19
  • 打赏
  • 举报
回复
在程序里也可以得到吗?鼠标应该用js在用户端比较好取吧
zgke 2009-01-19
  • 打赏
  • 举报
回复
private void Form1_Load(object sender, EventArgs e)
{
timer1.Tick+=new EventHandler(timer1_Tick);
timer1.Interval = 1;
timer1.Enabled = true;

}
private void timer1_Tick(object sender, EventArgs e)
{
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
if (webBrowser1.Document != null && webBrowser1.Document.Body != null)
{
int _Left = webBrowser1.Document.Body.Parent.ScrollRectangle.X;
int _Right = webBrowser1.Document.Body.Parent.ScrollRectangle.Y;

Rectangle _Rect = webBrowser1.RectangleToScreen(new Rectangle(0, 0, webBrowser1.Width, webBrowser1.Height));

if (_Rect.Contains(Cursor.Position))
{

int _X = Cursor.Position.X - _Rect.X;
int _Y = Cursor.Position.Y - _Rect.Y;

if (_X >= 0 && _Y >= 0)
{
Point _MousePoint = new Point(_X + _Left, _Y + _Right);
this.Text = _MousePoint.ToString();
}
}

}
}
}

这个看看效果...
U2008 2009-01-19
  • 打赏
  • 举报
回复
;;
leonwan 2009-01-19
  • 打赏
  • 举报
回复
up
yulien 2009-01-19
  • 打赏
  • 举报
回复
ding
cg2003 2009-01-19
  • 打赏
  • 举报
回复
UP
cannycsy 2009-01-19
  • 打赏
  • 举报
回复
zgke ,6楼的,在没有加载网页进入就可以取到位置,但如果加载入网址后怎么取得呢?

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧