C#UI自动化图片框和标签 [英] c# UI Automation picture box and label

查看:62
本文介绍了C#UI自动化图片框和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我使用Microsoft的UI自动化库已经有一段时间了,并且已经能够操作文本框和按钮.但是,我在某些控件上遇到了问题.

我有一个要自动化的程序,其中有一个图片框和一个链接标签,其功能类似于单击按钮.这意味着,如果我单击图片框或链接标签,则会触发一个事件,并定向到另一个页面.

我尝试使用按钮具有的invoke方法,但未成功.还有其他方法来触发点击事件或类似的图片框或链接标签吗?
提前谢谢.

Microsoft的UI自动化库:
http://msdn.microsoft.com/en-us/library/ms747327.aspx [ ^ ]

我正在使用的指南:
使用WPF的UI自动化框架 [

Hi,
I am using Microsoft''s UI Automation library for quite a while now, and I have been able to manipulate textboxes and buttons. However, I have problems with some of the controls.

I have a program that I want to automate, which have a picture box and a link label that functions like a button click. This means that if I clicked on the picture box or the link label, I will trigger an event, and be directed to another page.

I have tried using the invoke method, which buttons have, but was unsuccessful. Is there any other way to trigger the click event or something similar for a picture box or link label?
Thanks in advance.

Microsoft''s UI Automation library:
http://msdn.microsoft.com/en-us/library/ms747327.aspx[^]

The guide I am using:
UI Automation Framework using WPF[^]

推荐答案

如果您不介意迷路在UI自动化系统之外:

如果可以找到要单击的控件的窗口句柄(我相信自动化系统可以访问该窗口句柄),则可以使用Windows api将鼠标按钮向下发送,将鼠标按钮向上发送消息发送到控件句柄....这与实际单击控件非常相似.

它不是最优雅的解决方案.


If you don''t mind straying out of the UI Automation system:

If you can locate the window-handle of the control you want to click (I believe the automation system gives access to the window-handles), you could use the windows api to send a mouse-button down, and mouse-button-up message to the controls handle.... this is much the same as actually clicking the control.

Its not the most elegant solution though.


/// <summary>
/// sends a windows message to the specified window handle.
/// </summary>
/// <param name="hWnd">the window handle</param>
/// <param name="Msg">the message constant</param>
/// <param name="wParam">w parameter</param>
/// <param name="lParam">l parameter</param>
/// <returns>IntPtr Result</returns>
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);





public const int WM_LBUTTONDOWN = 0x201 ;
public const int WM_LBUTTONUP = 0x202  ;


这篇关于C#UI自动化图片框和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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