预览
代码
手机端效果
web端效果
demoWebView.cs
demoWebView.Designer.cs
web:demoWebView.cs
web:demoWebView.Designer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
using System.Data;
using System.IO;
namespace Smobiler.Tutorials.Samples
{
partial class demoWebView : Smobiler.Core.Controls.MobileForm
{
private void demoListViewRefresh_Load(object sender, EventArgs e)
{
//配合LocalHtml使用,生成文件
var localHtmlPath = Path.Combine(MobileResourceManager.DefaultWebPath, "demo.html");
if (File.Exists(localHtmlPath)==false)
{
using( FileStream stream= File.Create(localHtmlPath))
{
string demoHtml="<Html><Head></Head><Body>Hello LocalHtml</Body></Html>";
byte[] demoData=System.Text.Encoding.UTF8.GetBytes(demoHtml);
stream.Write(demoData,0,demoData.Length);
stream.Close();
}
}
//配合Dynamic使用
if (MobileServer.IsRegisterHttpHandler("dynamic")==false)
{
MobileServer.RegisterHttpHandler("dynamic", new DynamicHttpContentHandler());
}
}
private void title1_ImagePress(object sender, EventArgs e)
{
this.Close();
}
private void btnLocalHtml_Press(object sender, EventArgs e)
{
this.webView1.Url = MobileResourceManager.GetResourceURL(this.Client.SessionID, "web/demo.html");
}
private void btnDymaticHtml_Press(object sender, EventArgs e)
{
this.webView1.Url = MobileResourceManager.GetResourceURL(this.Client.SessionID, "dynamic");
}
private void btnSmobilerUrl_Press(object sender, EventArgs e)
{
this.webView1.Url = "www.smobiler.com";
}
}
class DynamicHttpContentHandler:Smobiler.Core.Web.IHttpHandler
{
public void ProcessRequest(System.Net.HttpListenerContext context, Smobiler.Core.Web.HttpHandlerData handlerdata)
{
string rawResponse=string.Format("<Html><Head></Head><Body>Hello Dynamic Time {0}</Body></Html>",DateTime.Now.ToString());
byte[] dataResponse= System.Text.Encoding.UTF8 .GetBytes(rawResponse);
context.Response.ContentLength64 = dataResponse.Length;
context.Response.StatusCode = 200;
context.Response.OutputStream.Write(dataResponse, 0, dataResponse.Length);
context.Response.OutputStream.Close();
}
}
}
using System;
using Smobiler.Core;
namespace Smobiler.Tutorials.Samples
{
partial class demoWebView : Smobiler.Core.Controls.MobileForm
{
#region "SmobilerForm generated code "
public demoWebView()
: base()
{
//This call is required by the SmobilerForm.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//SmobilerForm overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerForm
//It can be modified using the SmobilerForm.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.title1 = new Smobiler.Core.Controls.Title();
this.webView1 = new Smobiler.Core.Controls.WebView();
this.btnLocalHtml = new Smobiler.Core.Controls.Button();
this.btnDymaticHtml = new Smobiler.Core.Controls.Button();
this.btnSmobilerUrl = new Smobiler.Core.Controls.Button();
//
// title1
//
this.title1.ImageType = Smobiler.Core.Controls.ImageEx.ImageStyle.FontIcon;
this.title1.Name = "title1";
this.title1.ResourceID = "arrow-left";
this.title1.Size = new System.Drawing.Size(0, 30);
this.title1.Text = "demoWebViewLocal";
this.title1.ImagePress += new System.EventHandler(this.title1_ImagePress);
//
// webView1
//
this.webView1.Flex = 1;
this.webView1.Name = "webView1";
this.webView1.Size = new System.Drawing.Size(0, 300);
//
// btnLocalHtml
//
this.btnLocalHtml.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(190)))), ((int)(((byte)(80)))));
this.btnLocalHtml.FontSize = 15F;
this.btnLocalHtml.Name = "btnLocalHtml";
this.btnLocalHtml.Size = new System.Drawing.Size(0, 30);
this.btnLocalHtml.Text = "加载本地HTML文件";
this.btnLocalHtml.Press += new System.EventHandler(this.btnLocalHtml_Press);
//
// btnDymaticHtml
//
this.btnDymaticHtml.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(70)))), ((int)(((byte)(80)))));
this.btnDymaticHtml.FontSize = 15F;
this.btnDymaticHtml.Name = "btnDymaticHtml";
this.btnDymaticHtml.Size = new System.Drawing.Size(0, 30);
this.btnDymaticHtml.Text = "动态生成HTML内容";
this.btnDymaticHtml.Press += new System.EventHandler(this.btnDymaticHtml_Press);
//
// btnSmobilerUrl
//
this.btnSmobilerUrl.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(230)))), ((int)(((byte)(100)))));
this.btnSmobilerUrl.FontSize = 15F;
this.btnSmobilerUrl.Name = "btnSmobilerUrl";
this.btnSmobilerUrl.Size = new System.Drawing.Size(0, 30);
this.btnSmobilerUrl.Text = "修改为Smobiler官网链接";
this.btnSmobilerUrl.Press += new System.EventHandler(this.btnSmobilerUrl_Press);
//
// demoWebView
//
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.title1,
this.webView1,
this.btnLocalHtml,
this.btnDymaticHtml,
this.btnSmobilerUrl});
this.Layout = Smobiler.Core.Controls.LayoutPosition.Relative;
this.Load += new System.EventHandler(this.demoListViewRefresh_Load);
this.Name = "demoWebView";
}
#endregion
private Smobiler.Core.Controls.Title title1;
private Smobiler.Core.Controls.WebView webView1;
private Smobiler.Core.Controls.Button btnLocalHtml;
private Smobiler.Core.Controls.Button btnDymaticHtml;
private Smobiler.Core.Controls.Button btnSmobilerUrl;
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Smobiler.Core;
using Smobiler.Core.Controls;
namespace SmobilerTutorialsWeb.Components
{
partial class demoWebView : Smobiler.Core.Controls.MobileForm
{
public demoWebView() : base()
{
//This call is required by the SmobilerForm.
InitializeComponent();
}
private void title1_ImagePress(object sender, EventArgs e)
{
this.Close();
}
private void demoWebView_Load(object sender, EventArgs e)
{
//配合LocalHtml使用,生成文件
var localHtmlPath = Path.Combine(MobileResourceManager.DefaultWebPath, "demo.html");
if (File.Exists(localHtmlPath) == false)
{
using (FileStream stream = File.Create(localHtmlPath))
{
string demoHtml = "<Html><Head></Head><Body>Hello LocalHtml</Body></Html>";
byte[] demoData = System.Text.Encoding.UTF8.GetBytes(demoHtml);
stream.Write(demoData, 0, demoData.Length);
stream.Close();
}
}
//配合Dynamic使用
if (MobileServer.IsRegisterHttpHandler("dynamic") == false)
{
MobileServer.RegisterHttpHandler("dynamic", new DynamicHttpContentHandler());
}
}
private void btnLocalHtml_Press(object sender, EventArgs e)
{
this.webView1.Url = MobileResourceManager.GetResourceURL(this.Client.SessionID, "web/demo.html");
}
private void btnDymaticHtml_Press(object sender, EventArgs e)
{
this.webView1.Url = MobileResourceManager.GetResourceURL(this.Client.SessionID, "dynamic");
}
private void btnSmobilerUrl_Press(object sender, EventArgs e)
{
this.webView1.Url = "www.smobiler.com";
}
class DynamicHttpContentHandler : Smobiler.Core.Web.IHttpHandler
{
public void ProcessRequest(System.Net.HttpListenerContext context, Smobiler.Core.Web.HttpHandlerData handlerdata)
{
string rawResponse = string.Format("<Html><Head></Head><Body>Hello Dynamic Time {0}</Body></Html>", DateTime.Now.ToString());
byte[] dataResponse = System.Text.Encoding.UTF8.GetBytes(rawResponse);
context.Response.ContentLength64 = dataResponse.Length;
context.Response.StatusCode = 200;
context.Response.OutputStream.Write(dataResponse, 0, dataResponse.Length);
context.Response.OutputStream.Close();
}
}
}
}
using System;
using Smobiler.Core;
namespace SmobilerTutorialsWeb.Components
{
partial class demoWebView : Smobiler.Core.Controls.MobileForm
{
#region "SmobilerForm generated code "
//SmobilerForm overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
//NOTE: The following procedure is required by the SmobilerForm
//It can be modified using the SmobilerForm.
//Do not modify it using the code editor.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.title1 = new Smobiler.Core.Controls.Title();
this.panel1 = new Smobiler.Core.Controls.Panel();
this.labTitle = new Smobiler.Core.Controls.Label();
this.panel2 = new Smobiler.Core.Controls.Panel();
this.webView1 = new Smobiler.Core.Controls.WebView();
this.btnLocalHtml = new Smobiler.Core.Controls.Button();
this.btnDymaticHtml = new Smobiler.Core.Controls.Button();
this.btnSmobilerUrl = new Smobiler.Core.Controls.Button();
//
// title1
//
this.title1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(246)))), ((int)(((byte)(246)))), ((int)(((byte)(246)))));
this.title1.ImageType = Smobiler.Core.Controls.ImageEx.ImageStyle.FontIcon;
this.title1.Name = "title1";
this.title1.ResourceID = "angle-left";
this.title1.Size = new System.Drawing.Size(0, 30);
this.title1.Text = "WebView";
this.title1.ImagePress += new System.EventHandler(this.title1_ImagePress);
//
// panel1
//
this.panel1.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.labTitle,
this.panel2});
this.panel1.Flex = 1;
this.panel1.Name = "panel1";
this.panel1.Scrollable = true;
this.panel1.Size = new System.Drawing.Size(0, 100);
//
// labTitle
//
this.labTitle.BackColor = System.Drawing.Color.White;
this.labTitle.Bold = true;
this.labTitle.Border = new Smobiler.Core.Controls.Border(0F, 0F, 0F, 1F);
this.labTitle.BorderColor = System.Drawing.Color.White;
this.labTitle.FontSize = 16F;
this.labTitle.Location = new System.Drawing.Point(300, 30);
this.labTitle.Name = "labTitle";
this.labTitle.Size = new System.Drawing.Size(600, 26);
this.labTitle.Text = "网页浏览控件";
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.White;
this.panel2.Border = new Smobiler.Core.Controls.Border(1F);
this.panel2.BorderColor = System.Drawing.Color.Silver;
this.panel2.BorderRadius = 5;
this.panel2.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.webView1,
this.btnLocalHtml,
this.btnDymaticHtml,
this.btnSmobilerUrl});
this.panel2.Location = new System.Drawing.Point(300, 57);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(600, 572);
//
// webView1
//
this.webView1.Flex = 1;
this.webView1.Name = "webView1";
this.webView1.Size = new System.Drawing.Size(600, 359);
//
// btnLocalHtml
//
this.btnLocalHtml.Location = new System.Drawing.Point(19, 433);
this.btnLocalHtml.Name = "btnLocalHtml";
this.btnLocalHtml.Size = new System.Drawing.Size(150, 30);
this.btnLocalHtml.Text = "加载本地HTML文件";
this.btnLocalHtml.Press += new System.EventHandler(this.btnLocalHtml_Press);
//
// btnDymaticHtml
//
this.btnDymaticHtml.Location = new System.Drawing.Point(221, 433);
this.btnDymaticHtml.Name = "btnDymaticHtml";
this.btnDymaticHtml.Size = new System.Drawing.Size(150, 30);
this.btnDymaticHtml.Text = "动态生成HTML内容";
this.btnDymaticHtml.Press += new System.EventHandler(this.btnDymaticHtml_Press);
//
// btnSmobilerUrl
//
this.btnSmobilerUrl.Location = new System.Drawing.Point(423, 433);
this.btnSmobilerUrl.Name = "btnSmobilerUrl";
this.btnSmobilerUrl.Size = new System.Drawing.Size(150, 30);
this.btnSmobilerUrl.Text = "修改为Smobiler官网链接";
this.btnSmobilerUrl.Press += new System.EventHandler(this.btnSmobilerUrl_Press);
//
// demoWebView
//
this.BackColor = System.Drawing.Color.White;
this.Controls.AddRange(new Smobiler.Core.Controls.MobileControl[] {
this.title1,
this.panel1});
this.Layout = Smobiler.Core.Controls.LayoutPosition.Relative;
this.Size = new System.Drawing.Size(1200, 800);
this.Load += new System.EventHandler(this.demoWebView_Load);
this.Name = "demoWebView";
}
#endregion
private Smobiler.Core.Controls.Title title1;
private Smobiler.Core.Controls.Panel panel1;
private Smobiler.Core.Controls.Label labTitle;
private Smobiler.Core.Controls.Panel panel2;
private Smobiler.Core.Controls.WebView webView1;
private Smobiler.Core.Controls.Button btnLocalHtml;
private Smobiler.Core.Controls.Button btnDymaticHtml;
private Smobiler.Core.Controls.Button btnSmobilerUrl;
}
}