diff --git a/Examples/VideoPlayerController/VideoPlayerController/MainForm.cs b/Examples/VideoPlayerController/VideoPlayerController/MainForm.cs index 153f3e3..0d743f3 100644 --- a/Examples/VideoPlayerController/VideoPlayerController/MainForm.cs +++ b/Examples/VideoPlayerController/VideoPlayerController/MainForm.cs @@ -43,7 +43,9 @@ public enum Players /// private Players _player; - private OnScreenPopupForm _messageBox = new OnScreenPopupForm(); + private OnScreenPopupForm _messageBox = new OnScreenPopupForm() {DisplayAt = DisplayLocation.BottomLeft}; + + private OnScreenPopupForm _clockBox = new OnScreenPopupForm() {DisplayAt = DisplayLocation.TopRight, BackColor = Color.DarkSlateGray}; /// /// Used to lock the function critical section @@ -96,6 +98,9 @@ protected override void Dispose(bool disposing) _messageBox?.Dispose(); _messageBox = null; + _clockBox?.Dispose(); + _clockBox = null; + _device?.Disconnect(); _device = null; } @@ -180,6 +185,10 @@ private void SendKeysToWindow(Controller controller, Buttons buttons) if (!string.IsNullOrEmpty(keysToSend)) { SendKeys.SendWait(keysToSend); + + // Hack for fullscreen toggle + if( keysToSend == "f" ) + _clockBox.ShowMessage(DateTime.Now.ToString("HH:mm"), this); } else { diff --git a/Examples/VideoPlayerController/VideoPlayerController/OnScreenPopupForm.cs b/Examples/VideoPlayerController/VideoPlayerController/OnScreenPopupForm.cs index a6df4a0..cf7e1d0 100644 --- a/Examples/VideoPlayerController/VideoPlayerController/OnScreenPopupForm.cs +++ b/Examples/VideoPlayerController/VideoPlayerController/OnScreenPopupForm.cs @@ -12,13 +12,14 @@ namespace VideoPlayerController { - public partial class OnScreenPopupForm : Form { private Timer _hideTimer; public string Message { get { return lblMessage.Text; } private set { lblMessage.Text = value ?? string.Empty; } } + public DisplayLocation DisplayAt { get; set; } = DisplayLocation.BottomLeft; + public OnScreenPopupForm() { InitializeComponent(); @@ -65,22 +66,48 @@ private void lblMessage_VisibleChanged(object sender, EventArgs e) { if (!this.Visible) return; - - // If being shown then we want to place it in the lower bottom corner of the screen - int y = Screen.PrimaryScreen.Bounds.Bottom - this.Height; - this.Location = new Point(0, y); + + var loc = Point.Empty; + + switch (DisplayAt) + { + case DisplayLocation.BottomLeft: + // If being shown then we want to place it in the lower bottom corner of the screen + loc = new Point(0, + Screen.PrimaryScreen.Bounds.Bottom - this.Height); + break; + case DisplayLocation.TopRight: + loc = new Point(Screen.PrimaryScreen.Bounds.Right - this.Width, + Screen.PrimaryScreen.Bounds.Top); + break; + } + + // If no location is set then don't show the form + if (loc == Point.Empty) + return; + + this.Location = loc; this.TopMost = true; - // Start timer to hide form again in 5 sec - _hideTimer.Change(5000, Timeout.Infinite); + // Start timer to hide form again in x sec + _hideTimer.Change(3000, Timeout.Infinite); } public void ShowMessage(string message, IWin32Window parent = null) { this.Message = message; - if( !this.Visible ) + // Resize the form to better fit the text + this.Width = ((int) this.CreateGraphics().MeasureString(message, lblMessage.Font).Width) + 20; + + if ( !this.Visible ) this.Show(parent); } } + + public enum DisplayLocation + { + BottomLeft, + TopRight + } }