Groups | Blog | Home
all groups > dotnet jscript > july 2003 >

dotnet jscript : Web Browser in .Net Form


Chris R. Timmons
7/7/2003 1:36:32 PM
"Robert Chan" <robertchan1@hotmail.com> wrote in
news:eIVk#PLRDHA.2432@TK2MSFTNGP10.phx.gbl:

[quoted text, click to view]

Robbie,

The code you posted is C#. Are you trying to compile this with the
jsc.exe compiler?

Chris.
-------------
C.R. Timmons Consulting, Inc.
Robert Chan
7/7/2003 2:19:28 PM
I am having trouble converting this into a format that I can use in a
compiled .Net Jscript

The bottom line is that I am trying to incorporate a web browser control
inside a form. This code was from Visual Studio and it works.

The problem has to do with the reference to web browser component.

The compiler complains that it can't find AxSHDocVw. I have tried moving
the SHDocVw.dll into the directory and using:

jsc /r:shdocvw.dll test.js

Which does not cause an error, but still I can't get the proper reference to
the web browser component.

I have also tried import SHDocVw, which does not cause an error.

If it would be helpful, I will post the code I have that doesn't work. <g>

Thanks in advance.

Robbie


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
public class Form1 : System.Windows.Forms.Form
{
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
object a = 0;
object b = 0;
object c = 0;
object d = 0;
this.axWebBrowser1.Navigate("www.google.com",ref a,ref b,ref
c,ref d);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();

((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit()
;
this.SuspendLayout();
this.axWebBrowser1.Enabled = true;
this.axWebBrowser1.Location = new
System.Drawing.Point(40, 32);
this.axWebBrowser1.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxS
tate")));
this.axWebBrowser1.Size = new System.Drawing.Size(480,
456);
this.axWebBrowser1.TabIndex = 0;this.AutoScaleBaseSize
= new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(552, 502);
this.Controls.Add(this.axWebBrowser1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
this.ResumeLayout(false);
}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}


Chris R. Timmons
7/7/2003 4:47:39 PM
"Robert Chan" <robertchan1@hotmail.com> wrote in
news:eIVk#PLRDHA.2432@TK2MSFTNGP10.phx.gbl:

[quoted text, click to view]

Robert,

Please ignore my other reply from earlier today.

For general information on how to host the ActiveX web browser
control from ShDocVw.dll, please go here:

http://samples.gotdotnet.com/quickstart/aspplus/default.aspx?url=%2fq
uickstart%2fwinforms%2fdoc%2fWinFormsAxHosting.aspx

Following the steps given on that page, here is one way to create a
simple browser-enabled JScript.Net app:

1. Use the AxImp utility to create the .Net wrappers for the
ShDocVw.dll:

aximp c:\winnt\system32\shdocvw.dll

Place the two output files (shdocvw.dll and AxShDocVw.DLL) in the
folder where your JScript.Net source code will go.

2. Place the following JScript.Net code in a file named
"MainForm.js" in that folder:


import System;
import System.Drawing;
import System.Windows.Forms;

import AxSHDocVw;

Application.Run(new BrowserExample());

public final class BrowserExample extends Form
{
var AxWebBrowser1 : AxSHDocVw.AxWebBrowser;

public function BrowserExample()
{
this.Width = 400;
this.Height = 400;

this.AxWebBrowser1 = new AxSHDocVw.AxWebBrowser();
this.AxWebBrowser1.BeginInit();
this.AxWebBrowser1.Size = new System.Drawing.Size(292, 273);
this.AxWebBrowser1.TabIndex = 3;
this.AxWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(AxWebBrowser1);
this.AxWebBrowser1.EndInit();

this.AxWebBrowser1.Navigate("http://www.yahoo.com/");
}
}


3. Compile the application using this command line:

jsc /t:exe /r:system.dll /r:system.windows.forms.dll
/R:System.Drawing.DLL /R:shdocvw.dll /R:AxShDocVw.DLL mainform.js


I tried these steps with both .Net 1.0 and 1.1. Everything worked OK
on my system.

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
Bill Compton
7/7/2003 6:05:54 PM
The problem is he doesn't know how to reference the AsSHDocVw object in
Jscript.

The idea behind the post is to say:
This is how it is done in c#, how would you do it in .Net Jscript?

Bill

[quoted text, click to view]

Bill Compton
7/8/2003 5:04:55 PM
The sample you gave worked like a charm. Your effort has been HUGELY
helpful to me. I want you to know that I really appreciate you sharing your
knowledge here.

Thank you.

Bill


[quoted text, click to view]

Robert Chan
7/8/2003 9:30:05 PM
Just wanted to let you know that you were of great help.
Your sample worked perfectly.
thank you very much
-Robbie

[quoted text, click to view]

AddThis Social Bookmark Button