Skip to content

Instantly share code, notes, and snippets.

@davidwengier
Created October 29, 2020 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwengier/f0dcfa833e92726780a99f4086c27db8 to your computer and use it in GitHub Desktop.
Save davidwengier/f0dcfa833e92726780a99f4086c27db8 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
using SkiaSharp;
using SkiaSharp.Views.Desktop;
namespace HiDarran
{
public partial class HiDarran : System.Windows.Forms.Form
{
private readonly SKControl skView;
private bool runRenderLoop = true;
public HiDarran()
{
Text = "Hi Darran";
ClientSize = new System.Drawing.Size(800, 450);
skView = new SKControl();
skView.Dock = System.Windows.Forms.DockStyle.Fill;
Controls.Add(skView);
skView.PaintSurface += SkView_PaintSurface;
_ = PresentLoop();
}
private async Task PresentLoop()
{
while (runRenderLoop)
{
skView.Invalidate();
await Task.Delay(16).ConfigureAwait(true);
}
}
private void SkView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
e.Surface.Canvas.Clear(SKColors.White);
e.Surface.Canvas.DrawText("Hi Darran!", 100, 100, new SKPaint() { Color = SKColors.Black, TextSize = 25 });
e.Surface.Canvas.DrawText(DateTime.Now.ToString(), 200, 200, new SKPaint() { Color = SKColors.Black, TextSize = 25 });
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
runRenderLoop = false;
skView.Dispose();
}
base.Dispose(disposing);
}
}
}
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.Views.WindowsForms" Version="2.80.2" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HiDarran
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new HiDarran());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment