2016-12-07 18 views
0

私は、Awesomiumブラウザを通してWindowsフォーム内からTinyMceを使用しています。私は、Windowsフォーム上に配置しています。このようなユーザーコントロールを作成しました:Awesomium-vb.net htmlコンテンツを入手する

Imports System.Collections.Generic 
Imports System.ComponentModel 
Imports System.Drawing 
Imports System.Data 
Imports System.Text 
Imports System.Windows.Forms 
Imports System.IO 
Imports Awesomium.Core 
Imports Awesomium.Windows 

Partial Public Class TinyMCE 
    Inherits UserControl 

    Public Sub New() 
     InitializeComponent() 
    End Sub 

    Public Property HtmlContent() As String 
     Get 
      Dim content As String = String.Empty 

      If Not WebCore.IsInitialized Then 
       WebCore.Initialize(New WebConfig() With {.LogLevel = LogLevel.Verbose}) 
      Else 

       Dim html As JSValue = webBrowserControl.ExecuteJavascriptWithResult("GetContent") 

       content = html.ToString 

      End If 

      Return content 
     End Get 
     Set(value As String) 
      If WebCore.IsInitialized Then 
       Dim objResult As JSObject = webBrowserControl.ExecuteJavascriptWithResult("window") 
       objResult.InvokeAsync("SetContent", value) 
      End If 

     End Set 
    End Property 

    Public Sub CreateEditor() 
     If File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "html\template\tinymce\js\tinymce\tinymce.min.js")) Then 
      webBrowserControl.Source = New Uri("file:///" & Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "html\template\tinymce.htm").Replace("\"c, "/"c)) 
     Else 
      MessageBox.Show("Could not find the tinyMCE script directory. " & (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "html\template\tinymce\js\tinymce\tinymce.min.js")), "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error]) 
     End If 
    End Sub 
End Class 

私のHTMLは、限りのTinyMCEが行くようにかなり単純化され:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
    <title>tinyMCE WYSIWYG Editor</title> 
</head> 

<script type="text/javascript" src="tinymce/js/tinymce/tinymce.min.js"></script> 

<!-- Script functions to expose tinyMCE internals that get called from code using InvokeScript method. --> 
<script type="text/javascript"> 
    function GetContent() { 
    return tinyMCE.get('tinyMceEditor').getContent(); 
    } 

    function SetContent(htmlContent) { 
    tinyMCE.get('tinyMceEditor').setContent(htmlContent); 
    } 
</script> 

<!-- TinyMCE --> 
    <script type="text/javascript"> 
     tinymce.init({ 
      selector: 'textarea', 
      menu: { 
       file: { title: 'File', items: 'newdocument' }, 
       edit: { title: 'Edit', items: 'undo redo | cut copy paste pastetext | selectall' }, 
       insert: { title: 'Insert', items: 'link media | template hr' }, 
       view: { title: 'View', items: 'visualaid' }, 
       format: { title: 'Format', items: 'bold italic underline strikethrough superscript subscript | formats | removeformat' }, 
       table: { title: 'Table', items: 'inserttable tableprops deletetable | cell row column' }, 
       tools: { title: 'Tools', items: 'spellchecker code' }, 
       plantwatch: { title: 'My Menu', items: 'dataloop collectorloop processloop historian emailgroup alertgroup menusave' } 
      }, 
      menubar : 'plantwatch file edit insert view format table tools', 
      plugins: [ 
    'advlist autolink lists link image charmap print preview hr anchor pagebreak', 
    'searchreplace wordcount visualblocks visualchars code fullscreen', 
    'insertdatetime media nonbreaking save table contextmenu directionality', 
    'emoticons template paste textcolor colorpicker textpattern imagetools codesample toc' 
      ], 
      toolbar1: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image', 
      toolbar2: 'forecolor backcolor emoticons | codesample', 
      image_advtab: true, 

      setup: function (editor) { 
       editor.addMenuItem('dataloop', { 
        text: 'Data Loop', 
        onclick: function() { 
         editor.insertContent('{LOOP:Data}'); 
        } 
       }); 
       editor.addMenuItem('collectorloop', { 
        text: 'Collector Loop', 
        onclick: function() { 
         editor.insertContent('{LOOP:Collector}'); 
        } 
       }); 
       editor.addMenuItem('processloop', { 
        text: 'Process Loop', 
        onclick: function() { 
         editor.insertContent('{LOOP:Process}'); 
        } 
       }); 
       editor.addMenuItem('historian', { 
        text: 'Historian Server Name', 
        onclick: function() { 
         editor.insertContent('{HistorianServerName}'); 
        } 

       }); 
       editor.addMenuItem('emailgroup', { 
        text: 'Email Group Name', 
        onclick: function() { 
         editor.insertContent('{EmailGroupName}'); 
        } 

       }); 
       editor.addMenuItem('alertgroup', { 
        text: 'Alert Group Name', 
        onclick: function() { 
         editor.insertContent('{AlertGroupName}'); 
        } 
       }); 

      } 

     }); 


    </script> 
<!-- /TinyMCE --> 

<body> 
    <form method="post"> 
    <!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded --> 
     <textarea name="tinyMceEditor" cols="1" rows="1" style="width:100%; height: 78%"></textarea> 
    </form> 
</body> 
</html> 

私はその後、私のWindows上のボタンを持っています

プライベートサブのButton1 Click(オブジェクトとして送信者、EventArgsのようe)のハンドルButton1.Click のMsgBox(tinyMceEditor.HtmlContent) End Subの

:以下呼び出すフォーム210

私はコンテンツを返すようにすることを期待しているだろうが、その代わり、それはこれだけである関数自体の全文を、返却されます。

function GetContent() { 
     return tinyMCE.get('tinyMceEditor').getContent(); 
     } 

それがあるため、当然のことながら、文字列形式でそれを返していますそれは私のコードがどのように構造化したかです。私はなぜHTMLを返さないのか分かりません。

+0

あなたは私が私のコンテンツを取得するために、そのポストからの正確な方法を使用していていることがわかります。 Webbrowserコントロールでうまく動作しますが、Awesomiumでは動作しません。つまり、TinyMCEの問題ではありません。 – Andrew

+1

JSValue = WebBrowserControl.ExecuteJavascriptWithResult( "GetContent") 'を' Dim html As JSValue = webBrowserControl.ExecuteJavascriptWithResult( "GetContent();")に変更してみてください ' –

+0

これは答えです!ありがとうございました。 – Andrew

答えて

1

今ではGetContent関数を参照しているため、定義が返されます。結果を取得するには、関数を呼び出す必要があります。

変更を行います。

Dim html As JSValue = webBrowserControl.ExecuteJavascriptWithResult("GetContent")

Dim html As JSValue = webBrowserControl.ExecuteJavascriptWithResult("GetContent();‌​") 
関連する問題