FrmWebBase.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11. using Chromium;
  12. using Chromium.Event;
  13. using Chromium.WebBrowser;
  14. using Chromium.WebBrowser.Event;
  15. using CoreFS.CA06;using Pur.Entity;using Pur.Entity;
  16. namespace Pur.Pop_upWindow
  17. {
  18. public partial class FrmWebBase : FrmPmsBase
  19. {
  20. private string url;
  21. public string Url
  22. {
  23. get { return url; }
  24. set { url = value; }
  25. }
  26. Chromium.WebBrowser.ChromiumWebBrowser WebBrowser = null;
  27. public FrmWebBase()
  28. {
  29. InitializeComponent();
  30. InitBrowser();
  31. WebBrowser = new Chromium.WebBrowser.ChromiumWebBrowser();
  32. WebBrowser.BackColor = System.Drawing.Color.White;
  33. WebBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
  34. WebBrowser.Location = new System.Drawing.Point(0, 0);
  35. WebBrowser.Name = "WebBrowser";
  36. WebBrowser.RemoteCallbackInvokeMode = Chromium.WebBrowser.JSInvokeMode.Inherit;
  37. WebBrowser.Size = new System.Drawing.Size(1370, 520);
  38. WebBrowser.TabIndex = 2;
  39. WebBrowser.Text = "浏览";
  40. WebBrowser.ContextMenuHandler.OnBeforeContextMenu += (s, e1) =>
  41. {
  42. return;
  43. };
  44. this.Controls.Add(WebBrowser);
  45. WebBrowser.LifeSpanHandler.OnBeforePopup += (s, e1) =>
  46. {
  47. var ff = e1.PopupFeatures.AdditionalFeatures;
  48. };
  49. }
  50. private void FrmWebBase_Load(object sender, EventArgs e)
  51. {
  52. //WebBrowser.LoadUrl("http://music.baidu.com/");
  53. //WebBrowser.LoadUrl("http://localhost:8080/CoreBaseWeb/manager/login");
  54. OpenUrl();
  55. //WebBrowser webBrowser1 = new WebBrowser();
  56. //this.Controls.Add(webBrowser1);
  57. //webBrowser1.Dock = DockStyle.Fill;
  58. //webBrowser1.Navigate(url);
  59. }
  60. public void OpenUrl()
  61. {
  62. WebBrowser.LoadUrl(url);
  63. }
  64. private static void InitBrowser()
  65. {
  66. if (string.IsNullOrEmpty(CfxRuntime.LibCefDirPath))
  67. {
  68. var assemblyDir = System.IO.Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);
  69. Environment.CurrentDirectory = System.IO.Path.Combine(assemblyDir, @".\");
  70. if (CfxRuntime.PlatformArch == CfxPlatformArch.x64)
  71. CfxRuntime.LibCefDirPath = @"cef64";
  72. else
  73. CfxRuntime.LibCefDirPath = @"cef";
  74. Chromium.WebBrowser.ChromiumWebBrowser.OnBeforeCfxInitialize += ChromiumWebBrowser_OnBeforeCfxInitialize;
  75. ChromiumWebBrowser.OnBeforeCommandLineProcessing += ChromiumWebBrowser_OnBeforeCommandLineProcessing;
  76. Chromium.WebBrowser.ChromiumWebBrowser.Initialize();
  77. }
  78. }
  79. static void ChromiumWebBrowser_OnBeforeCommandLineProcessing(CfxOnBeforeCommandLineProcessingEventArgs e)
  80. {
  81. Console.WriteLine("ChromiumWebBrowser_OnBeforeCommandLineProcessing");
  82. Console.WriteLine(e.CommandLine.CommandLineString);
  83. }
  84. static void ChromiumWebBrowser_OnBeforeCfxInitialize(OnBeforeCfxInitializeEventArgs e)
  85. {
  86. e.Settings.LocalesDirPath = System.IO.Path.GetFullPath(@"cef\Resources\locales");
  87. e.Settings.ResourcesDirPath = System.IO.Path.GetFullPath(@"cef\Resources");
  88. e.Settings.LogSeverity = CfxLogSeverity.Verbose;
  89. e.Settings.BrowserSubprocessPath = System.IO.Path.GetFullPath(@"chromiumfxDemo.exe");
  90. }
  91. }
  92. }