In a Win32 C# App, we are using a AxInterop control, it has some buttons on it like Ok, Cancel,etc...now in the C# code when I call and open the window of that AxInterop I want to see how can I know that user clicked on Ok buttton for example in that control so I can handle some stuff in C# code....
You can only use whatever the control exposes. You cannot capture the control events if they do not capture your click and translate it to a custom click that you can handle.
If you don't have the control documentation you can examine the controls methods/properties/events ... pressing F2.
Related
I have a WebBrowser control shown in a custom task pane in an Microsoft Office Application-level add-in created in Visual Studio. The web page shown in the WebBrowser doesn't receive keyboard events that can be handled by JavaScript code, such as KeyUp. The same page shown in a comparable WebBrowser in a Form does receive keyboard events. The WebBrowser control itself doesn't seem to expose any events related to keyboard input, and I don't seem to be able to handle keyboard events by adding event handlers to the UserControl added as a custom task pane.
I have created a minimal example – a Visual Studio solution – which recreates the problem.
Is there any way to pass on keyboard events to the web page?
Yup, you can do it. You'll have to hook into the HTML DOM events (like onclick, onmouseover, etc.). Take a look here: http://www.w3schools.com/jsref/dom_obj_event.asp.
And there's an example here:
http://www.codeproject.com/Articles/547451/WebBrowser-Element-Events-and-Values
I think you'll have to add a reference to the MSHTML library. BTW, put the WebBrowser control in a Panel control or it will act goofy - especially with keyboard events.
Actually I found a solution is to use the WebBrowser under Excel namespace
https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.controls.webbrowser.aspx
Obviously it is subclassing the windows form WebBrowser and fix the keyboard issues by handing some windows message manually.
I have a WebBrowser control in a WPF application. The browser control is in a grid and when the WebBrowser control renders some webpages, in one of the pages there is popup alert box from the webpage, and when the user taps on the popup the WebBrowser control seems to be closed. I need to capture this close event and take some action.
I already tried subscribing to the unload event but it does not seem to fire. Is there any way to get this event captured?
There is WindowClosing event on the underlying WebBrowser ActiveX control for that. I haven't tried it myself, but I think it should work.
Here's a full-fledged sample showing how handle the "underlying" WebBrowser events like that. It's for WPF, but it can be easily adapter for WinForms (using WebBrowser.ActiveXInstance).
How can i get the control (and possibly its text value) of a control which was clicked in another third party application (its not a .net or wpf application for which there are answers which did not solve my problem)
I can get the click event in my app (using the global hooks as mentioned here) i want the control/handle of that particular UI Element
Example : I have opened Notepad and when i click on File Menu, i want the control of that File button.
Look at the documentation for SetWindowsHookEx using the WH_CALLWNDPROC param. This will let you intercept messages in Notepad window procedure. You'll need to figure out which messages get generated from clicking the menu items in Notepad, you can use Spy++ for that. But there is no real control for the File button, it is part of a menu.
Do you know how to do click on a specific screen text?
I need to do click on a text inside a GUI Object from a external application; I need to automate this with C#. What is the reference that I need to this? I'm new in C#
You need to learn two tricks to accomplish this:
How to find the HWND (the handle) to the window that you want to send the click event to. There are some APIs in the Forms namespace to help with this or you can use PInvoke.
How to send the appropriate windows messages (WM_MOUSEDOWN, WM_MOUSEUP) using SendMessage.
Put these two together and you should be able to simulate a click event.
A custom windows form control named 'tweet' is in a dll. The custom control has couple of basic controls to display a tweet. I add this custom control to my main application. This custom control has a button named "retweet", when some user clicks this "retweet" button, i need to send some message to the main application. Unfortunately the this tweet control has no idea about this main application (both or in their own namespaces)
How can i send messages from this custom control to the main application?
One way is to add an event to your control and have the control fire that event when it needs to send a message. The main form can add an event handler when it creates the form and be notified of the messages. This way your control does not need to have any hard-coded reference to the main form.
You raise and handle the event. See the code sample on this page (you might have to choose the language on the page to be C#)
http://msdn.microsoft.com/en-us/library/9aackb16(v=VS.71).aspx