Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more: , +
Im working on an application for Windows 8.1 Tablet PC and I'm using a windows form and a WebBrowser control and load an HTML page into it. So, after the HTML page loads and when I click on a textbox control of the HTML page the Keyboard should pop up. My question is which event of the webbrowser control should I write the code to invoke the Touch Keyboard? Any other ideas on how can I invoke the keyboard when Textbox is clicked is appreciated. Thanks in advance!!
Posted

1 solution

Hello,

I had a project with exactly the same requirement and this is how I did it:

1) write a javascript to invoke the keyboard:
C#
function PopupKeyboard() {
    try{
        var focusedElement = document.activeElement; // Store the focused element.
        if (focusedElement.readOnly == false) {
            var shell = new ActiveXObject("WScript.Shell");
            var r = shell.Run('"C:/Program Files/Common Files/microsoft shared/ink/tabtip.exe"', 0, true); // This last param is for the execution of the script to stop until the program run in the shell exits. It doesn't work for tabtip.
            setTimeout(function () { // Wait 100 miliseconds before settting the focus again.
                if (focusedElement != null)
                    focusedElement.focus();
            }, 100);
        }
    } catch (Exception) { }
    return false;
}


Then write a little helper method to invoke the script:
private static void SetOnClickEvent(ControlCollection controls)
{
	Control childControl = default(Control);
	foreach ( childControl in controls) {
		if (childControl is TextBox) {
			TextBox textbox = (TextBox)childControl;
			textbox.Attributes("onclick") = "PopupKeyboard()";

		} else if (childControl is GridView) {
			GridViewRow row = default(GridViewRow);
			foreach ( row in ((GridView)childControl).Rows) {
				SetOnClickEvent(row.Controls);
			}
		}
		SetOnClickEvent(childControl.Controls);
	}
}


Call the helper in the load event of the pages

SetOnClickEvent(page.Controls)


Valery.
 
Share this answer
 
Comments
Member 10969557 28-Aug-14 9:51am    
Valery Thank you for the solution... I have another scenario... I will be loading a Clientele web application(Java based) into the web browser later... In that case, I wont have access to add the Javascript code to their pages. How should I invoke touch keyboard when a textbox is clicked in the web application running on my app web browser?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900