5
Answers

How to convert HTML elements to windows controls!!!!!! (Any possibility?)

Photo of Mena raj

Mena raj

14y
3.3k
1

I have about 100 XML files(with XSL that will convert each one of them to HTML )
I am planning to use a webbrowser control to fetch the "*.html" file.
At the same time i want the HTML elements in webbrowser to act based on some event.
which means if i press some button outside webbrowser, the HTML element say a textbox should have its TEXT value changed to something else.
Its very important for me to handle HTML elements event based on its properties and value.
Please offer some ideas or solutions if anyone knows. (cas i dont find a hint anywhere else)
THANKS A BUNCH!
 

Answers (5)

1
Photo of Tuhin Paul
39 34.6k 314.6k 2y

sample code

private void Form1_Load(object sender, EventArgs e)
{
    // Load the HTML file into the WebBrowser control
    webBrowser1.Navigate("path/to/html/file.html");
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    // Inject the JavaScript code to modify the text of the textbox element
    webBrowser1.Document.InvokeScript("eval", new object[] { @"
        var textbox = document.getElementById('textbox-id');
        textbox.value = 'new value';
    "});
}

replace 'path/to/html/file.html' with the path to your HTML file, and 'textbox-id' with the ID of the textbox element you want to modify.

1
Photo of Tuhin Paul
39 34.6k 314.6k 2y

One possible solution is to use JavaScript to modify the HTML elements in the web browser control. You can inject the JavaScript code into the HTML file using the WebBrowser control's DocumentText property or Navigate method.

0
Photo of Sam Hobbs
55 29.4k 2.1m 2y

Update: Note that this question is more than 12 years old!

0
Photo of Sam Hobbs
55 29.4k 2.1m 2y

This might depend on whether you need to do the conversion once or if you need to do a conversion every time the XML files change.

I think the best solution would be to convert the XSL to do a different conversion, such as convert the XML to XAML.

0
Photo of Deepak Rawat
122 15k 847.5k 2y

No Not possible to directly convert HTML elements to Windows controls.