How can I get feedback/interaction from the .NET WebBrowser control? - c#

I am building some kind of eBook reader in C# and have the following problem. Rendering HTML in the WebBrowser control just works fine. However, I want to be able to mark text samples with the mouse. This should be available via a button event or (even better) by click-and-drag directly onto the text. How can I get the feedback of the mouse events in the WebControl (and also the selected text)? Are there any examples around?
In a further step I want toe be able to insert notes as well (maybe by HTML injection)
I tried to get it to work with the WebControl, but had not a lot of success. Maybe some of you know a different approach (Gecko, Webkit?).

You already have DOM of the document loaded, and all you need to mark the samples is to modify the the source using DOM. DOM is, roughly speaking is a tree, that represents html source of WebBrowser control.
See IHTMLDocument2 . It's all not so complicated..

Related

Write into website cell using c# or WPF application

I have a very strange request that might upset some of you, anyway I want to write text or numbers in the website using C# or wpf software.
What I want is I pass string or number to the website when I press for example F11 on the keyboard and that number or string can be from a textbox.
Assume the following is Grid on a website:
Now I want to pass 0.01233 from textbox, to the highlighted cell in the website using c#.
Can anyone please how this can be achieved or at least guide me which direction I should go and achieve this.
Please Note I am not a developer of website and I have no control on website, I cannot write script on website
I've done something like this before, though I can't seem to find my old code. WPF has a WebBrowser control. You can use the Document property to access elements of the webpage an (if I recall correctly) execute scripts assosiated with those elements.
Of course it goes without saying that this would be a bodge at best, since any change made to the website could break your code.
Also, this forces you to use the WPF WebBrowser instead of your browser of choice.

How can I open a webpage first and then fill in text boxes and click a button and visibly view the results?

[edit] It is a requirement that the webpage spawn and open in IE and allow user manual interaction after the programmatic actions have completed.[/edit]
I've seen a lot of code examples online about opening webpages or filling in webpage textboxes and getting a return value without ever opening them visibly.
I would like to open a webpage in IE, fill in a few textbox buttons
and then click the submit button and view the results visibly.
I am able to do this with a dll called Selenium, but I do not want to use a 3rd party application and it seems that WebBrowser() should be able to do this?
I can post my failed code examples if that would help.
Thanks.
Maybe this qould fit better as a comment, but I don't have enoigh reputation.
Do you know how HTTP-Forms work?
It would probably be easier to send a HTTP-Request to the target of the form you want to fill, including the parameters you would like to fill into the form.
So you don't need any WebBrowser or similar, just a simple HttpWebRequest object, where you specity the target, the method (very likely POST) and the data you'd like to send.
You can use the webbrowser control in Winforms. It is possible to access every DOM object of the website using the control. No need to open the IE externally.
You just need to specify the webbrowser URL as your link.
Then, fill the textboxes with code,
BrowserID.Document.GetElementById("TextboxID").SetAttribute("Value", "NewVaue")
Also, you can click on the button using InvokeMember("click").
There are lots of stuff using WebBrowser. You can learn it here.

Windows Phone browser live html modification

I haven't looked into it very much but am struggling to find relevant information on the topic. I basically want to create a browser that applies a filter to a webpage by changing colors in a webpage. My guess is that I will have to change the html once loaded or something, would this work? Do I have other options?
PS. I don't just want to make every color darker, I would more like to invert the colors.
Edit:
If any you were wondering, I am talking about the XAML browser component that can be used in a Windows Phone application.
I think the simplest way to do that is to inject some Javascript into your page once it has loaded.
To do that, you need to set the IsScriptEnabled to true on your WebBrowser control and then subscribe to the Navigated event.
When that event occurs you can inject some JS codeby using the WebBrowser.InvokeScript method.
Here is an example of JS code that darken the page : JavaScript: Invert color on all elements of a page
If you are talking about in a PC internet browser, you can find an add-on to execute Javascript automatically, such as Greasemonkey for Firefox. If you are talking about Windows Phone's Internet Explorer, I don't really know what you could do there, as I don't think they allow add-ons.

Accessing DOM from WebBrowser

I am trying to implement a browser-like little application that would allow me to modify the viewed web-sites appearance (e.g. make the font for links bigger). It is designed for Microsoft Surface, to be used on a huge touchscreen. It uses WPF for the UI.
I am intending to use a WebBrowser control for this task. However there are two classes called WebBrowser in the docs. One of them is in System.Windows.Forms, the other in System.Windows.Controls. The first one gives access to DOM model, but is intended for Forms applications (if I understand correctly, that's definitely not what I have). The second one is added by default if you add the controller in xaml, but it gives no access to the DOM.
So, how do I access the DOM model from a WebBrowser for Surface? I am very new to c# and Microsoft technologies, so I apologise if my question is unclear or obvious.
For the System.Windows.Controls.WebBrowser class you can use the Document property.
Add mshtml reference to your project that should be available by right click on project and selecting Add Reference, then you should be able to cast it to mshtml.IHTMLDocument2
mshtml.IHTMLDocument2 htmlDoc = webBrowser.Document as mshtml.IHTMLDocument2;
// do something like find button and click
htmlDoc.all.item("testBtn").click();

How to render a Awesomium webview on a Canvas (or any other UI)?

How can I render a WebView to a WPFCanvas in Awesomium 1.7? (using C#)
In the previous version of Awesomium, I used to use a WebControl and add it as a child of a canvas. Now I want to use Isolated Sessions, which seems possible in v1.7, but I can't display it. Also, should I be using Webcontrol along with WebSessions and WebViews? I'm clueless as there are not many sample out there yet.
Any help would be appreciated!
You are able to use WebControls with isolated sessions, either programmatically by setting the WebControl.WebSession property (it's read-write on WebControls), or by using a WebSessionProvider in XAML. Read more here: http://wiki.awesomium.net/general-use/using-web-sessions.html

Categories

Resources