TizzyT

Photino Net 6 Example

Mar 23rd, 2022 (edited)
2,652
0
Never
8
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Drawing;
  5. using System.Threading;
  6. using System.Runtime.InteropServices;
  7. using PhotinoNET;
  8.  
  9. using static System.Threading.Thread;
  10. using static System.Runtime.InteropServices.RuntimeInformation;
  11.  
  12. // ===== You really only need this part =====
  13. if (IsOSPlatform(OSPlatform.Windows)
  14.     && CurrentThread.GetApartmentState() != ApartmentState.STA)
  15. {
  16.     if (!CurrentThread.TrySetApartmentState(ApartmentState.Unknown)
  17.         || !CurrentThread.TrySetApartmentState(ApartmentState.STA))
  18.     {
  19.         throw new Exception("Unable to set ApartmentState.STA");
  20.     }
  21. }
  22. // ==========================================
  23.  
  24. PhotinoWindow window = new PhotinoWindow()
  25. {
  26.     Title = "Photino for .NET Demo App",
  27.     UseOsDefaultSize = false,
  28.     Size = new Size(1280, 720),
  29.     Centered = true,
  30.     Resizable = true,
  31. }
  32. .RegisterCustomSchemeHandler("app", (object sender, string scheme, string url, out string contentType) =>
  33. {
  34.     contentType = "text/javascript";
  35.     return new MemoryStream(
  36.         Encoding.UTF8.GetBytes(
  37.             @"(() => window.setTimeout(() => alert(`🎉 Dynamically inserted JavaScript.`), 1000))();"));
  38. })
  39. .RegisterWebMessageReceivedHandler((object sender, string message) =>
  40. {
  41.     PhotinoWindow window = sender as PhotinoWindow;
  42.     string response = $"Received message: \"{message}\"";
  43.     window.SendWebMessage(response);
  44. })
  45. .Load("wwwroot/index.html");
  46.  
  47. window.WaitForClose();
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment