简体   繁体   中英

C# Winforms Custom WebBrowser Control Needed

I have been searching the web lately for an existing control that acts like a web browser control, with some specific features that I need.

I haven't found one that has them, and so I wanted to leave a question here, hoping that someone can point out how I can do this, or even give me some tips on how to create one from scratch, which will ultimately be the solution.

I need a control that allows me to preview webpages, at the same time it allows me to edit it programatically. I don't need to write HTML or text directly into the editor, but need to be able to click a button, and insert specific HTML code to the document, and refresh the preview.

I also need to be able to capture click events on the control. For example, I want to click a specific place on the control and get the HTML element that is at the mouse position. Regarding events, I would also need to be able to capture drag-and-drop, and it seems that natively, the browser control doesn't also support this.

Even though I have tried out some different controls, none of them has these features, or allowed me to add them. So, I would really appreciate if someone could point me to the right direction, or maybe correct me if I am wrongly assuming it can't be done with any of the existing .NET controls.

Thank you in advance for any help.

Two suggestions:

On the browser's client-side there are DOM accessors that will let you get HTML by mouse position. Check out this page for a demonstration of this:

http://www.permadi.com/tutorial/cssGetElementUnderMouse/index.html

Presumably you could write out javascript into your HTML that would have hooks in it to raise events in your parent UI code that could in turn interact with the browser. Getting something that captures the HTML element name from the DOM, and passes it back to the UI, which uses it as a cursor into an HTMLDocument would be a good start.

From there you could probably extend that model to support ideas like drag/drop or on-the-fly refresh or what have you.

I don't know of anything that does this out of the box. I did look around and come across this tool, which is billing itself as free and is providing source, but I don't know what its license model is so contact the author .

http://kompozer.net/features.php

As far as I know, there is no such control. Moreover, writing one from scratch, that correctly rendered all modern HTML/CSS would be a major undertaking.

Even products like Microsoft Expression tends to have quirks in the way they display the HTML being edited.

I'm afraid you've got your work cut out for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM