How to make navigation form with WebBrowser control in the development of C/s mode

Source: Internet
Author: User

I believe that many students have done MIS system development, here today does not discuss the B/S model development problem. To talk about WinForm development.
Used to market the common invoicing system students must know that after entering the system generally in the MDI form the system automatically opens a navigation subform.
Display some common features in a very intuitive graphic to the user.
Observe such products on the market, this feature is basically a prerequisite function form for all the management systems that are developed by MDI forms. Let's look at how to do this in. Net. Fortunately, I did a similar system last time, which also uses the navigation function. I hereby dedicate my own development experience.
Haha, just look at the text is not very tired ah, may be a lot of students do not know. A navigation form effect picture first.
The following is a screenshot of a. NET developed invoicing system.


Isn't it cool?
How do you do that? Now there are generally two ways:
1. Through the GDI or PictureBox, such as mapping + complex programming implementation. Very troublesome, slow.
2. Implement the interface through the Web. Using code to get Web events, interface and program separation is achieved. Very convenient, and fast.
The first is needless to say, and few companies are going to do that now. Here's the second one, the subject of this article.
When it comes to adding web pages to WinForm, we naturally think of WebBrowser controls.
Look at MSDN help, which has an important attribute, Document (HTMLDocument Class), and continue to view msdn,htmldocument there is an important way: Invokescript, look at the MSDN explanation: executing in HTML Dynamic scripting functions defined in the page.
^_^, do you see the light? This method can easily handle the Web page JS code in the WebBrowser control.
So we can easily call the JS function in C # to control the Web page.
But how do you implement the way code in a Web page calls C #? You can view the MSDN ComVisibleAttribute class:
The control program centralizes the accessibility of individual managed types, members, or all types to COM.

That is, we only need to introduce the System.Runtime.InteropServices namespace in the WinForm form.
Precede the form class and the method that needs to be invoked with the property declaration [ComVisible (true)]

How does the specific code implement?
Examples of methods in WinForm are:
[ComVisible (True)]
public void OpenForm (string formName)
{
if (string. IsNullOrEmpty (FormName))
Return
Switch (formName)
{
Case "PurchaseOrder":
Form_purchaseorder frm = new Form_purchaseorder ();
frm. Show ();
Break
Case "Saleorder":
Form_saleorder Frm1 = new Form_saleorder ();
Frm1. Show ();
Break
Case "Form1":
Form1 frm2 = new Form1 ();
Frm2. Show ();
Break
}
}
In JS you can call this method: <input type= "button" onclick= "Window.external.OpenForm (' PurchaseOrder ')" value= "Purchase Order" >

Is it simple? No detailed implementation code is posted here, please ask me for the detailed code

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.