Spring – Rev 1
?pathlinks?
using System;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsInput;
using Gma.System.MouseKeyHook;
using Spring.Main;
using Spring.Utilities;
namespace Spring.Tutorial
{
public partial class Tutorial : Form
{
#region Public Enums, Properties and Fields
public IKeyboardMouseEvents KeyboardMouseEvents { get; set; }
public InputSimulator InputSimulator { get; }
public MainForm Form { get; }
public int Slide { get; set; }
#endregion
#region Constructors, Destructors and Finalizers
public Tutorial()
{
InitializeComponent();
Utilities.WindowState.FormTracker.Track(this);
InputSimulator = new InputSimulator();
}
public Tutorial(MainForm springMainForm, IKeyboardMouseEvents keyboardMouseEvents) : this()
{
Form = springMainForm;
KeyboardMouseEvents = keyboardMouseEvents;
KeyboardMouseEvents.KeyUp += KeyboardMouseEvents_KeyUp;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
KeyboardMouseEvents.KeyUp -= KeyboardMouseEvents_KeyUp;
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
#region Event Handlers
private void Form_Move(object sender, EventArgs e)
{
RelocateTutorial();
}
private async void KeyboardMouseEvents_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Space:
await NextSlide();
break;
case Keys.Escape:
Close();
break;
}
}
private async void Tutorial_Load(object sender, EventArgs e)
{
RelocateTutorial();
await NextSlide();
}
private void RichTextBox1_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = true;
}
#endregion
#region Private Methods
private void RelocateTutorial()
{
var springLocation = Form.Location;
Location = new Point(springLocation.X + Form.Size.Width, springLocation.Y);
}
private async Task NextSlide()
{
try
{
++Slide;
var rtf = Encoding.UTF8.GetString(await Helpers.LoadResource($"Spring.Tutorial.Slides.{Slide}.rtf"));
richTextBox1.Rtf = rtf;
}
catch
{
Close();
}
}
#endregion
}
}