Creating A Simple Web Browser Using DotNet
In the following example, you will create a simple Web Browser using the WebBrowser
DotNet control provided by System.Windows.Forms
First, create a simple MAXScript rollout and add a dotNetControl called wb that uses
the System.Windows.Forms.WebBrowser control.
Then, open the rollout as a dialog - the WebBrowser will be empty.
EXAMPLE
|
rollout webbrowser_rollout "Web Test" width:600 height:600
(
dotNetControl wb "System.Windows.Forms.WebBrowser" pos:[10,10] width:580 height:580
)
createdialog webbrowser_rollout
|
Now, set a default URL for the browser to open at. To see what properties are available
in the WebBrowser control, you can call show Properties() on the control:
CODE
|
showPropertieswebbrowser_rollout.wb
|
RESULT
|
.AccessibilityObject : <System.Windows.Forms.AccessibleObject>, read-only
.AccessibleDefaultActionDescription : <System.String>
.AccessibleDescription : <System.String>
.AccessibleName : <System.String>
.AccessibleRole : <System.Windows.Forms.AccessibleRole>
.ActiveXInstance : <System.Object>, read-only
.AllowDrop : <System.Boolean>
.AllowNavigation : <System.Boolean>
.AllowWebBrowserDrop : <System.Boolean>
.Anchor : <System.Windows.Forms.AnchorStyles>
.AutoScrollOffset : <System.Drawing.Point>
.AutoSize : <System.Boolean>
.BackColor : <System.Drawing.Color>
.BackgroundImage : <System.Drawing.Image>
.BackgroundImageLayout : <System.Windows.Forms.ImageLayout>
.BindingContext : <System.Windows.Forms.BindingContext>
.Bottom : <System.Int32>, read-only
.Bounds : <System.Drawing.Rectangle>
.CanFocus : <System.Boolean>, read-only
.CanGoBack : <System.Boolean>, read-only
.CanGoForward : <System.Boolean>, read-only
.CanSelect : <System.Boolean>, read-only
.Capture : <System.Boolean>
.CausesValidation : <System.Boolean>
.CheckForIllegalCrossThreadCalls : <System.Boolean>, static
.ClientRectangle : <System.Drawing.Rectangle>, read-only
.ClientSize : <System.Drawing.Size>
.CompanyName : <System.String>, read-only
.Container : <System.ComponentModel.IContainer>, read-only
.ContainsFocus : <System.Boolean>, read-only
.ContextMenu : <System.Windows.Forms.ContextMenu>
.ContextMenuStrip : <System.Windows.Forms.ContextMenuStrip>
.Controls : <System.Windows.Forms.Control+ControlCollection>, read-only
.Created : <System.Boolean>, read-only
.Cursor : <System.Windows.Forms.Cursor>
.DataBindings : <System.Windows.Forms.ControlBindingsCollection>, read-only
.DefaultBackColor : <System.Drawing.Color>, read-only, static
.DefaultFont : <System.Drawing.Font>, read-only, static
.DefaultForeColor : <System.Drawing.Color>, read-only, static
.DisplayRectangle : <System.Drawing.Rectangle>, read-only
.Disposing : <System.Boolean>, read-only
.Dock : <System.Windows.Forms.DockStyle>
.Document : <System.Windows.Forms.HtmlDocument>, read-only
.DocumentStream : <System.IO.Stream>
.DocumentText : <System.String>
.DocumentTitle : <System.String>, read-only
.DocumentType : <System.String>, read-only
.Enabled : <System.Boolean>
.EncryptionLevel : <System.Windows.Forms.WebBrowserEncryptionLevel>, read-only
.Focused : <System.Boolean>, read-only
.Font : <System.Drawing.Font>
.ForeColor : <System.Drawing.Color>
.Handle : <System.IntPtr>, read-only
.HasChildren : <System.Boolean>, read-only
.Height : <System.Int32>
.ImeMode : <System.Windows.Forms.ImeMode>
.InvokeRequired : <System.Boolean>, read-only
.IsAccessible : <System.Boolean>
.IsBusy : <System.Boolean>, read-only
.IsDisposed : <System.Boolean>, read-only
.IsHandleCreated : <System.Boolean>, read-only
.IsMirrored : <System.Boolean>, read-only
.IsOffline : <System.Boolean>, read-only
.IsWebBrowserContextMenuEnabled : <System.Boolean>
.LayoutEngine : <System.Windows.Forms.Layout.LayoutEngine>, read-only
.Left : <System.Int32>
.Location : <System.Drawing.Point>
.Margin : <System.Windows.Forms.Padding>
.MaximumSize : <System.Drawing.Size>
.MinimumSize : <System.Drawing.Size>
.ModifierKeys : <System.Windows.Forms.Keys>, read-only, static
.MouseButtons : <System.Windows.Forms.MouseButtons>, read-only, static
.MousePosition : <System.Drawing.Point>, read-only, static
.Name : <System.String>
.ObjectForScripting : <System.Object>
.Padding : <System.Windows.Forms.Padding>
.Parent : <System.Windows.Forms.Control>
.PreferredSize : <System.Drawing.Size>, read-only
.ProductName : <System.String>, read-only
.ProductVersion : <System.String>, read-only
.ReadyState : <System.Windows.Forms.WebBrowserReadyState>, read-only
.RecreatingHandle : <System.Boolean>, read-only
.Region : <System.Drawing.Region>
.Right : <System.Int32>, read-only
.RightToLeft : <System.Windows.Forms.RightToLeft>
.ScriptErrorsSuppressed : <System.Boolean>
.ScrollBarsEnabled : <System.Boolean>
.Site : <System.ComponentModel.ISite>, write-only
.Size : <System.Drawing.Size>
.StatusText : <System.String>, read-only
.TabIndex : <System.Int32>
.TabStop : <System.Boolean>
.Tag : <System.Object>
.Text : <System.String>
.Top : <System.Int32>
.TopLevelControl : <System.Windows.Forms.Control>, read-only
.UseWaitCursor : <System.Boolean> .Version : <System.Version>, read-only .Visible
: <System.Boolean> .WebBrowserShortcutsEnabled : <System.Boolean> .Width : <System.Int32>
.WindowTarget : <System.Windows.Forms.IWindowTarget>
|
You can see that there is a property URL exposed by the control. Assume that this
is the property to set for accessing a web page.
The type of the value expected by the DotNet control is System.Uri. This means that
you will have to convert the URL MAXScript String value to a dotNetObject value of
the expected type:
CODE
|
webbrowser_rollout.wb.url = dotNetObject "System.Uri" "http://www.autodesk.com"
|
Now, if your computer has Internet access, the Web Browser displays the Autodesk homepage:
A Web Browser requires at least an address text field so that the user can enter other
URLs. You can easily transform our first script into a more advanced Web Browser by
adding a MAXScriptedittext control and some event handlers:
SCRIPT
|
rollout webbrowser_rollout "Web Test" width:600 height:600
(
edittext edt_url "URL:" text:"http://www.autodesk.com"
dotNetControl wb "System.Windows.forms.WebBrowser" pos:[10,22] width:580 height:570
fn openURL urlString = (
wb.url = dotNetObject "System.Uri" urlString )
on edt_url entered txt do openURL txt
on webbrowser_rollout open do openURL edt_url.text
)
createdialog webbrowser_rollout
|
Try typing in other URLs in the text field and see your Web Browser opening them.