System.Windows.Forms によって提供される WebBrowser DotNet コントロールを使用して、簡単な Web ブラウザを作成する例を以下に示します。
まず、簡単な MAXScript ロールアウトを作成し、次に System.Windows.Forms.WebBrowser コントロールを使用する wb という dotNetControl を追加します。
次に、このロールアウトをダイアログ「WebBrowser」(中身はありません)として開きます。
例:
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
開くブラウザに、既定の URL を設定します。WebBrowser コントロールで使用できるプロパティを確認したい場合は、同コントロールについて show Properties() を呼び出します。
コード
showPropertieswebbrowser_rollout.wb
結果
.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> .Url : <System.Uri>
このコントロールによって公開されるプロパティ「URL」が存在することがわかります。これが、Web ページにアクセスするために設定するプロパティであると仮定します。
DotNet コントロールが期待する値のタイプは System.Uri です。このため、URL MAXScript 文字列の値を、期待されるタイプの dotNetObject 値に変換する必要があります。
コード
webbrowser_rollout.wb.url = dotNetObject "System.Uri" "http://www.autodesk.com"
お使いのコンピュータがインターネットにアクセスできる場合、Web ブラウザには Autodesk のホームページが表示されます。
Web ブラウザには、少なくとも、ユーザが他の URL を入力するためのアドレス テキスト フィールドが必要です。MAXScript の edittext コントロールといくつかのイベント ハンドラを追加することによって、最初に作成したスクリプトを簡単により高度な Web ブラウザにすることができます。
スクリプト:
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
テキスト フィールドに他の URL を入力し、この Web ブラウザに正しく表示されることを確認してみましょう。