My first blog post (use of Winfrom under WebBrowser controls)

Source: Internet
Author: User

To tell the truth to the blog Park also has more than 2 years, but a piece of article has not written. Just because the mood is very bad today, decided to take advantage of break time to write a blog post to relax. The text is really a very magical thing, write to feel the mood will be much better. I now have an idea is to put my summary of some of the technical things to slowly put in the blog park.

Why are you in a bad mood today, because I am late in the morning. This late estimate is the third time I am late this month, so I am afraid of the company bulletin. It was a detour this morning because of road roads. Usually it is 20 minutes away, this morning actually took 40 minutes. Depends on, why the traffic jam Ah, why always in the right turn or turn left when the block. Look at the traffic lights so inclined to go straight car, I really want to kick the door smashed glass. I kept urging the driver to hurry up, and by 50 we had a meeting. But really to no shadow mountain in the road, I despair, already nearly 8 o'clock, fully late 10 minutes. I am not so angry, accept the fate of it. My colleague was very calm along the way, in the back to the daughter-in-law called, silently waiting for the arrival of late. Alas, in the future must be in the bell rang on the wake up, because perhaps will encounter delays in the event, to set aside the time to solve the problem.

Well, it's not bothering me now. The first article can not just grumble, write something useful. I've been working on WinForm and Android for a while, and I'm going to make sure that my skills are improved before the new year comes. For Android Learning, I am ready to block, first realize some of the functions commonly used in mobile phones. When you are familiar with Android, write some fun things that you want to achieve. In the future I will realize a small function in this garden, but also for the future review with, perhaps a long time, this is wealth.

And not prepared for what was written today, it suddenly occurred to me that one of yesterday's things, the use of the WebBrowser control:

For beginners, I don't usually have much contact with this control. Recently wanted to implement a nested Web page in WinForm, displaying list data from a Web page. The communication problem between WinForm and WebForm is used because of the need for data problems in downloading Web pages. Search from the garden a lot, finally found a solution.

Accessing elements in the WebForm in 1.winform and adding events

This is quite simple, for example:

Content in WebForm:

1 <HTML>2 <Body>3   <inputID= "Btndownload"type= "button"value= "Download and open" />4 </Body>5 </HTML>
View Code

Content in WinForm:

Because WinForm accesses the contents of the WebBrowser control, it needs to be loaded after the WebBrowser control document has finished loading.

Therefore, you need to write the calling code under DocumentCompleted time (documentcompleted: Occurs when a document that is hosted in a Web browser control is loaded all. )

1 Private voidWebbrowser1_documentcompleted (Objectsender, WebBrowserDocumentCompletedEventArgs e)2 {3HTMLDocument HD = webbrowser1.document;//This is the document object in the Get WebBrowser control4hd. getElementById ("Btndownload"). Click + =NewHtmlelementeventhandler (btndownload_htmlelementevent);//Add the Click event to the button in the document5 }6 7 //This is a custom method, which is the function to be implemented after click.8 voidBtndownload_htmlelementevent (Objectsender, HtmlElementEventArgs e)9 {TenMessageBox.Show ("I'm not angry now."); One}
View Code

which

hd. getElementById is one of the methods of capturing elements, and when it comes out with a dot, you can usually see the smart hints of VS when you navigate to the method name, and generally understand how this is done.


In the garden, the blogger about the use of WebBrowser control is very full, there is time for everyone to see
Http://www.cnblogs.com/peterzb/archive/2009/07/12/1521787.html

Methods for accessing WinForm in 2.webform

1 <HTML>2 <Body>3  <DivID= "DataList">4    <ul>5      <Li><Ponclick= "Window.external.showDetails (12178)">Why are you late today, I'm so angry.</P></Li>6 7      <Li><Ponclick= "Window.external.showDetails (12306)">Later I decided to ring up, no longer procrastinate.</P></Li>8 9    </ul>Ten  </Div> One </Body> A </HTML>
View Code

Content in WinForm:

1 usingSystem.Security.Permissions;2 3[PermissionSet (SecurityAction.Demand, Name ="FullTrust")]4[System.Runtime.InteropServices.ComVisibleAttribute (true)]5  Public Partial classForm1:form6 {7 8         PublicForm1 ()9        {Ten InitializeComponent (); OneWebbrowser1.objectforscripting = This; A  -        } -  the } -  - //The custom method in WinForm, the method that JS needs to be called in the WebBrowser control -  +  Public voidShowDetails (intinfoid) - { +Frmdetails FD =Newfrmdetails (); AWebBrowser WB = (WebBrowser) fd. controls["WebBrowser1"]; atWb. Navigate ("###?id="+infoid); - FD. ShowDialog (); -}
View Code

I will not explain, copy to VS, the mouse to the code, look at the smart tips, a look will understand what is the use of the.

My first blog post (use of Winfrom under WebBrowser controls)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.